Anshu Jain
Anshu Jain

Reputation: 1

add jobs using curl

Hello I am using php curl to add jobs in http://www.alliedtravelcareers.com/feed/jobs.php, I am passing all the parameters using curl method but I am getting error as "No POST data was found! Please send data using the POST method.". I am sending data using curl

$data = '<?xml version="1.0" encoding="utf-8"?>
<source>
<apiKey>apikey</apiKey>
<method>add</method>
<jobs>
<job>
<jobId><![CDATA['.rand(1,9999).']]></jobId>
<title><![CDATA['.$job_desc->return->dto->title.']]></title>
<city><![CDATA['.$job_desc->return->dto->address->city.']]></city>
<state><![CDATA['.$job_desc->return->dto->address->state.']]></state>
<license><![CDATA['.$job_desc->return->dto->title.']]></license>
</job>
</jobs>
</source>';



$url = "http://www.alliedtravelcareers.com/feed/jobs.php";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT,40000000000000000); 
$output = curl_exec($ch);
curl_close($ch);

I am sending data properly in curl but still it show me error of No post data found.

Please help me I have tried many changes in curl but not getting success.

Upvotes: 0

Views: 121

Answers (1)

jeroen
jeroen

Reputation: 91734

You need to post a key - value pair and you are just posting the value.

You can probably use something like:

...
$datastring = 'data=' . urlencode($data);
curl_setopt($ch, CURLOPT_POSTFIELDS, $datastring);
...

if the name of the variable is supposed to be data and the value your xml string.

Upvotes: 1

Related Questions