Send JSON POST request with PHP

You can use CURL for this purpose see the example code: $url = “your url”; $content = json_encode(“your data to be sent”); $curl = curl_init($url); curl_setopt($curl, CURLOPT_HEADER, false); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_HTTPHEADER, array(“Content-type: application/json”)); curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_POSTFIELDS, $content); $json_response = curl_exec($curl); $status = curl_getinfo($curl, CURLINFO_HTTP_CODE); if ( $status != 201 ) { … Read more

Returning header as array using Curl

Here, this should do it: curl_setopt($this->_ch, CURLOPT_URL, $this->_url); curl_setopt($this->_ch, CURLOPT_HEADER, 1); curl_setopt($this->_ch, CURLOPT_RETURNTRANSFER, 1); $response = curl_exec($this->_ch); $info = curl_getinfo($this->_ch); $headers = get_headers_from_curl_response($response); function get_headers_from_curl_response($response) { $headers = array(); $header_text = substr($response, 0, strpos($response, “\r\n\r\n”)); foreach (explode(“\r\n”, $header_text) as $i => $line) if ($i === 0) $headers[‘http_code’] = $line; else { list ($key, $value) = … Read more

understanding php curl_multi_exec

You can explore two article that describes this example. PHP and curl_multi_exec First, here’s the high level. There are two outer loops. The first one is responsible for clearing out the curl buffer right now. The second one is responsible for waiting for more information, and then getting that information. This is an example of … Read more

How can I send SOAP XML via Curl and PHP?

Thanx a lot buddy, your code has worked for me. Here is the code: $soap_do = curl_init(); curl_setopt($soap_do, CURLOPT_URL, $url ); curl_setopt($soap_do, CURLOPT_CONNECTTIMEOUT, 10); curl_setopt($soap_do, CURLOPT_TIMEOUT, 10); curl_setopt($soap_do, CURLOPT_RETURNTRANSFER, true ); curl_setopt($soap_do, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($soap_do, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($soap_do, CURLOPT_POST, true ); curl_setopt($soap_do, CURLOPT_POSTFIELDS, $post_string); curl_setopt($soap_do, CURLOPT_HTTPHEADER, array(‘Content-Type: text/xml; charset=utf-8’, ‘Content-Length: ‘.strlen($post_string) )); curl_setopt($soap_do, CURLOPT_USERPWD, $user … Read more

When using –negotiate with curl, is a keytab file required?

Being a once-in-a-while-contributor to curl in that area. Here is what you need to know: curl(1) itself knows nothing about Kerberos and will not interact neither with your credential cache nor your keytab file. It will delegate all calls to a GSS-API implementation which will do the magic for you. What magic depends on the … Read more