What will be the equivalent to following curl command in java -


i need convert following curl command java command.

$curl_handle = curl_init ();  curl_setopt ($curl_handle, curlopt_url,$url);`enter code here` curl_setopt ($curl_handle, curlopt_followlocation, 1); curl_setopt ($curl_handle, curlopt_returntransfer, 1); curl_setopt ($curl_handle, curlopt_ssl_verifypeer, 0); curl_setopt ($curl_handle, curlopt_post, 1); curl_setopt ($curl_handle, curlopt_postfields, $postfields);  //echo $postfields;  $curl_result = curl_exec ($curl_handle) or die ("there has been curl_exec error"); 

http(s)urlconnection may weapon of choice:

public string senddata() throws ioexception {     // curl_init , url     url url = new url("http://some.host.com/somewhere/to/");     httpurlconnection con = (httpurlconnection) url.openconnection();      //  curlopt_post     con.setrequestmethod("post");      // curlopt_followlocation     con.setinstancefollowredirects(true);      string postdata = "my_data_for_posting";     con.setrequestproperty("content-length", string.valueof(postdata.length()));      con.setdooutput(true);     con.setdoinput(true);      dataoutputstream output = new dataoutputstream(con.getoutputstream());     output.writebytes(postdata);     output.close();      // "post data send ... waiting reply");     int code = con.getresponsecode(); // 200 = http_ok     system.out.println("response    (code):" + code);     system.out.println("response (message):" + con.getresponsemessage());      // read response     datainputstream input = new datainputstream(con.getinputstream());     int c;     stringbuilder resultbuf = new stringbuilder();     while ( (c = input.read()) != -1) {         resultbuf.append((char) c);     }     input.close();      return resultbuf.tostring(); } 

i'm not quite sure https_verifypeer-thing, may give starting point.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -