Alternative for HTTPRequest in php
httprequest, php
Solution
You can use CURL in php like this:
$ch = curl_init( $url );
$data_string = " ";
curl_setopt( $ch, CURLOPT_POSTFIELDS, $data_string );
curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
$result = curl_exec($ch);
curl_close($ch);
return $result;
and empty data string doesn't make sense in post request, but i've checked it with empty data string and it works quiet well.
Problem
I am using the HttpRequest class in my php script, but when I uploaded this script to my hosting provider's server, I get a fatal error when executing it: Fatal error: Class 'HttpRequest' not found in ... on line 87 I believe the reason is because my hosting provider's php.ini configuration doesnt include the extension that supports HttpRequest. When i contacted them they said that we cannot install the following extentions on shared hosting. So i want the alternative for httpRequest which i make like this: ``` $url= http://ip:8080/folder/SuspendSubscriber?subscriberId=5 $data_string=""; $request = new HTTPRequest($url, HTTP_METH_POST); $request->setRawPostData($data_string); $request->send(); $response = $request->getResponseBody(); $response= json_decode($response, true); return $response; ``` Or How can i use this request in curl as it is not working for empty datastring?