How do I POST Json value and some other values to another url using PHP
Get the solution ↓↓↓Solution:
JSON POST with jQuery:
http://api.jquery.com/jQuery.ajax/
I found this example on another stack overflow question:
$.ajax({ type: "POST",
url: "[URL of JSON-aware endpoint]", // your POST target goes here
dataType: "json",
data: { [$jsonRequest, $time, $hash] },
// message to send goes here
success: function (data)
{
// do something with result
}
});
</script>
You had a follow-up question about how to pass the jsonRequest AND the two other parameters $time and $hash.
Note that even though you had 3 parameters $time, $hash and $jsonRequest... because the ajax post argument is simply json... you can add all three parameters in the data argument for the $.ajax function like I did above:data: [$jsonRequest, $time, $hash]
I modified the example above to do this.
Answer
Solution:
Server-side only PHP solution:
See this link: http://themekraft.com/getting-json-data-with-php-curl/
You can use a combination of PHP curl and json_encode to send JSON and recieve JSON as a response.
$ch = curl_init( $json_url );
$json_string = json_encode(array(1 => $jsonRequest, 2 => $time, 3 => $hash));
$options = array( CURLOPT_RETURNTRANSFER => true,
CURLOPT_USERPWD => $username . ":" . $password,
CURLOPT_HTTPHEADER => array('Content-type: application/json'),
CURLOPT_POSTFIELDS => $json_string);
curl_setopt_array( $ch, $options );
$result = curl_exec($ch);
$json_result = json_decode($result);
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: unable to determine current zabbix database version: the table "dbversion" was not found.
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.