I have my code like this.
<?php
$post_vars = array('app_key'=>'my_api_key', 'user_key' => 'my_user_key');
$c = curl_init();
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_POST, 1);
curl_setopt($c, CURLOPT_HTTPHEADER, array('Accept: application/json', 'Content-Type: application/json'));
curl_setopt($c, CURLOPT_URL, 'http://hellotxt.com/api/v1/method/user.validate');
curl_setopt($c, CURLOPT_POSTFIELDS, $post_vars);
$content = curl_exec($c);
print_r($content);
curl_close($c);
?>
This display a return response as “app key not specified”.
But the same works if i post the api key and user key via a form (form-post).
When i submit the api key and user key using a form i get the response as.
<rsp status="OK"><nick>testinguser</nick><name>testinguser</name><avatar> http://hellotxt.com/avatar/testinguser/medium/image.jpg</avatar></rsp>
But i could not do with the curl. What went wrong.
Please guide me
Thanks
Haan
(PS:FYI, the api for hellotxt is here. http://hellotxt.com/developers/api)
you should send an array as post fields, now you are sending a json encoded string
so you should replace this:
with
where
Edit: also consider the answer Honoki gave.. I voted up because he has a point also, you need to “tell” curl that you plan to send post