PHP cURL "HTTP Version Mismatch" trouble with XML API

Hi, I’m having some frustrating issues trying to parse Indeed.com’s XML API on my server using PHP. They only allow HTTP GET, and not POST. I’ve tried using both cURL and PHP-DOM and am getting the same error. Here’s my code:

(removed my Publisher number for security reasons…)

[code]$publisher = “XXXXXXXXXXXXXXXX”;
$sort = “relevance”; ## Sort by “relevance” or “date”
$radius = “50”; ## Distance from search location
$st = “”; ## Site type (default blank- can set to “jobsite” or “employer”)
$jt = “”; ## Job type (default blank- can set to fulltime, parttime, contract, internship, or temporary)
$start_number = 0; ## Start search results at this number (used for pagination)
$limit = “10”; ## Number of results per page
$fromage = “”; ## Number of days to search back (default blank = 30)
$highlght = “1”; ## Bold the keyword search terms in results (set to 0 for no bold)
$filter = “1”; ## Filters out duplicate results (set to 0 for no filter)
$latlong = “0”; ## If latlong=1, returns latitude and longitude information for each result
$co = “us”; ## Country to search jobs in
$chnl = “”; ## API Channel request. Leave blank for none
$userip = $_SERVER[‘REMOTE_ADDR’]; ## IP address of user
$useragent = $_SERVER[‘HTTP_USER_AGENT’]; ## User’s browser type

$data = "http://api.indeed.com/ads/apisearch?";

$data .= “publisher=” . $publisher . “&”;
$data .= “q=” . $_SESSION[keyword] . “&”;
$data .= “l=” . $_SESSION[location] . “&”;
$data .= “sort=” . $sort . “&”;
$data .= “radius=” . $radius . “&”;
$data .= “st=” . $st . “&”;
$data .= “jt=” . $jt . “&”;
$data .= “start=” . $start_number . “&”;
$data .= “limit=” . $limit . “&”;
$data .= “fromage=” . $fromage . “&”;
$data .= “highlight=” . $highlight . “&”;
$data .= “filter=” . $filter . “&”;
$data .= “latlong=” . $latlong . “&”;
$data .= “co=” . $co . “&”;
$data .= “chnl=” . $chnl . “&”;
$data .= “userip=” . $userip . “&”;
$data .= “useragent=” . $useragent;

$ch = curl_init($data);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_HTTPGET, 1);
curl_setopt($ch, CURL_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);

$response = curl_exec($ch);

curl_close($ch); [/code]

And this is the error I’m getting every time, no matter what I do (even when I try to force the CURL_HTTP_VERSION):

HTTP/1.1 400 Bad Request Connection: close Content-Type: text/html Content-Length: 139 Bad Request Bad Request. Http version mismatch.

The URL that is built is vaild, because when I copy/paste it in my browser, it pulls up the XML Response I’m looking for.

Can anyone help me out with this? Am I missing something completely obvious? Can I not even use cURL for something like this? Thanks in advance!

-Ryan

Sponsor our Newsletter | Privacy Policy | Terms of Service