Situation:
I have a script with php in which I am receiving some data, with that data I create a JSON and that JSON I need to send it by POST with php5 (pure, no framework) to a web service in an online site.
I found that it can be done with php5-curl, but since it's a hostinig service that the site is on, I can not install those packages.
My question:
Is there a way to do that JSON sending only using php? and if so, could you tell me how to do it or where or how to look for it? because I only encounter as a do but with php5-curl.
Thank you very much, but I was referring a little bit more to this, but still thanks for answering:)
$postData = array(
'kind' => 'blog',
'blog' => '3',
'title' => 'A new post',
'content' => 'With <b>exciting</b> content...'
);
// Create the context for the request
$context = stream_context_create(array(
'http' => array(
'method' => 'POST',
'header' => "Authorization: application/json\r\n".
"Content-Type: application/json\r\n",
'content' => json_encode($postData)
)
));
// Send the request
$response = file_get_contents('http://www.example.com/blogger/blog/posts/', FALSE, $context);
// Check for errors
if($response === FALSE){
die('Error');
}
Now the detail that I have is that it always enters the condition, that is to say that it always returns false, I'm not sure if it is the webservices that is returning that or does not even try to send the json, suggestions? Help please! : C
In this line is where I do not know what it is doing, if it does not go out or the web service returns that ... I'll go more to do not send data.
$response = file_get_contents('http://www.example.com/blogger/blog/posts/', FALSE, $context);
I gave a var_dump to $response
and it returns me bool(false)