简体   繁体   English

PHP Curl问题

[英]Issue with PHP Curl

I have an issue with CURL in the below code. 我在以下代码中遇到CURL的问题。 The Hyperlink i'm an generating at the bottom if clicked is producing the correct output from the API (displaying an XML file in Browser) 如果单击该链接,我将是底部的超链接,它会从API产生正确的输出(在浏览器中显示XML文件)

However when sending via CURL no response is achieved. 但是,通过CURL发送时,没有响应。 Any idea what i'm missing here? 知道我在这里缺少什么吗? Is there anything i can do in terms of more error checking? 我可以做更多的错误检查吗?

(Application Key Obviously Removed) (显然删除了应用程序密钥)

<?

$APIKey = '123456';
$maxResponseTime = '5000';
$maxResultCount = '5';
$Brand = 'OTB';
$DepartureAirport = 'LON';
$DestinationResort = 'Magaluf';
$DepartureDate = '2015-09-08';
$HolidayMinNights = '7';
$HolidayMaxNights = '7';
$DaysEitherSide = '3';
$PassengerCounts_Adults = '2';







$QueryString = "APIKey=".$APIKey."&maxResponseTime=".$maxResponseTime."&maxResultCount=".$maxResultCount."&Brand=".$Brand."&DepartureAirport=".$DepartureAirport."&DestinationCountry=&DestinationRegion=&DestinationResort=".$DestinationResort."&DepartureDate=".$DepartureDate."&HolidayMinNights=".$HolidayMinNights."&HolidayMaxNights=".$HolidayMaxNights."&Board=&StarRatingMin=&StarRatingMax=&DaysEitherSide=".$DaysEitherSide."&PassengerCounts_Adults=".$PassengerCounts_Adults."&PassengerCounts_Children=0&PassengerCounts_ChildAge=&PassengerCounts_Infants=0 ";
$QueryString2 = 'http://v2.feeds.distributenetwork.net/singlebrand.asmx/GetDeals?'.$QueryString;

// Get cURL resource
$curl = curl_init();
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1 ); 
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true );
curl_setopt ($curl, CURLOPT_URL, $QueryString2);

// Send the request & save response to $resp
$resp = curl_exec($curl);

if(!curl_exec($curl)){
 echo('Error: "' . curl_error($curl) . '" - Code: ' . curl_errno($curl));
}
// Close request to clear up some resources
curl_close($curl);

echo $resp;


///Generate Manual Link To Complete Get Request In Browser
echo '<br><br><a href='.$QueryString2.'>A Manual Link Which Works When Clicked</a>';


?>

您的问题是在$QueryString结尾的空格中将其删除,它将起作用=)

you have problems with spaces, use http_build_query 您在空格方面遇到问题,请使用http_build_query

$queryArr = array(
    "APIKey"                 => '123456',
    "maxResponseTime"        => '5000',
    "maxResultCount"         => '5',
    "Brand"                  => 'OTB',
    "DepartureAirport"       => 'LON',
    "DestinationResort"      => 'Magaluf',
    "DepartureDate"          => '2015-09-08',
    "HolidayMinNights"       => '7',
    "HolidayMaxNights"       => '7',
    "DaysEitherSide"         => '3',
    "PassengerCounts_Adults" => '2',
    "DestinationCountry"     => '',
    "DestinationRegion"      => '',
    "DestinationResort"      => '',
    "board"                  => '',
    "StarRatingMin"          => '',
    "StarRatingMax"          => '',
    "PassengerCounts_Children" => '',
    "PassengerCounts_ChildAge" => '',
    "PassengerCounts_Infants"  => ''

);

define("BASE_URL",'http://v2.feeds.distributenetwork.net/singlebrand.asmx/GetDeals?');

// Get cURL resource
$curl = curl_init();
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1 ); 
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true );
curl_setopt ($curl, CURLOPT_URL, BASE_URL.http_build_query($queryArr));

// Send the request & save response to $resp
$resp = curl_exec($curl);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM