2

I am trying to use jobcrank feeds api and it requires data to be sent in headers I want to make request in the following format

POST /v2/QueryService.asmx/QueryJob HTTP/1.1
Host: api.jobcrank.com
Content-Type: application/x-www-form-urlencoded
Content-Length: length

and the query parameters will be sent in following method

apiKey=string&apiSerial=string&serviceTypeID=string&jobType=string&keyWordsType=string&keyWords=string&stateAbbreviation=string&county=string&city=string&isWorkFromHome=string

I have written code also for this but dont know how to send header containing "POST /v2/QueryService.asmx/QueryJob HTTP/1.1" line Here is my code:`

<?php
        $fields = array(
    'apiKey'=>'XXX',
    'apiSerial'=>'XXXX',);
$fields_string="";
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string,'&');
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,'/v2/QueryService.asmx/QueryJob');
curl_setopt($ch,CURLOPT_POST,count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
$result = curl_exec($ch);
print $result;
?>

3 Answers 3

1

CURLOPT_URL requires an absolute URL with scheme and host:

curl_setopt($ch, CURLOPT_URL,'http://example.org/v2/QueryService.asmx/QueryJob');
Sign up to request clarification or add additional context in comments.

Comments

0

You don't need to set this header - it is being done automatically. What you however need to do is to urlencode your $fields_string, because it may contain forbidden characters like white space. To do this, use http_build_query to build this string directly from your array:

$fields_string = http_build_query($fields);

It will urlencode the values and make the valid post string.

Comments

0

You don't have to explicitly add POST header. Curl will do that for you, just set CURLOPT_POST flag to true and that is it.

curl_setopt ($ch, CURLOPT_POST, TRUE);

Have a look at this site when in doubt: http://php.net/curl_setopt

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.