Как получить данные XML с помощью запроса RESTful POST? - PullRequest
0 голосов
/ 28 июля 2011

У меня проблемы с получением XML от службы данных healthdata.gov (http://healthindicators.gov/Developers/). Ниже я использую php CURL для выполнения запроса POST, причем мой запрос является строкой xml. Я ожидаю получить xmlданные возвращаются. Я получаю сообщение об ошибке от службы, в котором говорится, что я не установил тип содержимого на «application / xml», что я и сделал!

Healthdata.gov - это огромные и важные данныеисточник, но, как ни странно, их документация нелегка (для меня), чтобы понять. Кто-нибудь удалось получить данные из этого сервиса?

Заранее спасибо (код ниже, заявка здесь: http://cd47ddcc.dotcloud.com).

#index.php

//set URL
$url = 'http://services.healthindicators.gov/v2/REST.svc/Indicators/Filter';

//set xml request
$xml = '
<SearchQuery xmlns="http://schemas.datacontract.org/2004/07/S3.Common.Search" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
    <Mode>And</Mode>
    <Elements>
        <SearchElement i:type="SearchParameter">
            <Name>IndicatorDescriptionID</Name>
            <Operator>Equal</Operator>
            <Value>15</Value>
        </SearchElement>
        <SearchElement i:type="SearchParameter">
            <Name>LocaleID</Name>
            <Operator>Equal</Operator>
            <Value>39</Value>
        </SearchElement>
    </Elements>
    <Page>1</Page>
</SearchQuery>
';

// Get the curl session object
$session = curl_init($url);

// set url to post to 
//curl_setopt($session, CURLOPT_URL,$url);
// Tell curl to use HTTP POST;
curl_setopt ($session, CURLOPT_POST, true);
// Tell curl that this is the body of the POST
curl_setopt ($session, CURLOPT_POSTFIELDS, $xml);
// Tell curl not to return headers, but do return the response
curl_setopt($session, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type: application/xml; charset=utf-8"));
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
// allow redirects 
//curl_setopt($session, CURLOPT_FOLLOWLOCATION, true);

$response = curl_exec($session);
//print_r ($response);

echo "<h1>Health Data</h1><br />";
echo $response;
echo "<hr />";

curl_close($session);
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...