0

I have an issue with CURL in the below code. 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)

However when sending via CURL no response is achieved. 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>';


?>
2
  • What do you call sending to CURL?I dont see any sending. Commented Aug 3, 2015 at 14:58
  • What does echo curl_error($curl); return? php.net/manual/en/function.curl-error.php - If it's XML, wrap things in <pre></pre> and htmlentities. Commented Aug 3, 2015 at 14:59

2 Answers 2

1

Your problem is in the space at the end of $QueryString remove it and it will work =)

Sign up to request clarification or add additional context in comments.

1 Comment

Oh my goodness! Such a simple answer, it was because of the very long string running off the screen! Thane So Much!!
1

you have problems with spaces, use 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);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.