How to send PUT, DELETE HTTP request in HttpURLConnection?

To perform an HTTP PUT: URL url = new URL(“http://www.example.com/resource”); HttpURLConnection httpCon = (HttpURLConnection) url.openConnection(); httpCon.setDoOutput(true); httpCon.setRequestMethod(“PUT”); OutputStreamWriter out = new OutputStreamWriter( httpCon.getOutputStream()); out.write(“Resource content”); out.close(); httpCon.getInputStream(); To perform an HTTP DELETE: URL url = new URL(“http://www.example.com/resource”); HttpURLConnection httpCon = (HttpURLConnection) url.openConnection(); httpCon.setDoOutput(true); httpCon.setRequestProperty( “Content-Type”, “application/x-www-form-urlencoded” ); httpCon.setRequestMethod(“DELETE”); httpCon.connect();

RAW POST using cURL in PHP

I just found the solution, kind of answering to my own question in case anyone else stumbles upon it. $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, “http://url/url/url” ); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 ); curl_setopt($ch, CURLOPT_POST, 1 ); curl_setopt($ch, CURLOPT_POSTFIELDS, “body goes here” ); curl_setopt($ch, CURLOPT_HTTPHEADER, array(‘Content-Type: text/plain’)); $result = curl_exec($ch);

Curl and PHP – how can I pass a json through curl by PUT,POST,GET

PUT $data = array(‘username’=>’dog’,’password’=>’tall’); $data_json = json_encode($data); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HTTPHEADER, array(‘Content-Type: application/json’,’Content-Length: ‘ . strlen($data_json))); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, ‘PUT’); curl_setopt($ch, CURLOPT_POSTFIELDS,$data_json); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($ch); curl_close($ch); POST $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HTTPHEADER, array(‘Content-Type: application/json’)); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS,$data_json); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($ch); curl_close($ch); … Read more