curl - How to make a https post in Java? -
hello being developer beginning in world of java want know how write equivalent of curl in java.
curl -x post \ -h "authorization:basic sisi" \ -d "grant_type=client_credentials" \ "https://api.orange.com/oauth/v2/token"
you can use apache httpclient implement in java.
one example -
string url = "https://api.orange.com/oauth/v2/token"; httpclient client = httpclientbuilder.create().build(); httppost post = new httppost(url); post.setheader("authorization", "basic sisi"); httpresponse response = client.execute(post); bufferedreader rd = new bufferedreader(new inputstreamreader(response.getentity().getcontent())); stringbuffer result = new stringbuffer(); string line = ""; while ((line = rd.readline()) != null) { result.append(line); } //print result
read more here - http://www.mkyong.com/java/apache-httpclient-examples/
Comments
Post a Comment