user1315906
user1315906

Reputation: 3494

POST to a HTTPS service

I need to know how to POST to a HTTPS web service. I went through the tutorial but it didn't help because it is too old.

Can anyone please help me out by giving me a good tutorial or some sample code to start with?

Upvotes: 1

Views: 1060

Answers (2)

Michael
Michael

Reputation: 35341

Something like this:

URL url = new URL("https://..."); 
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
connection.setDoInput(true); 
connection.setDoOutput(true);
connection.setRequestMethod("POST");

//write the request body
OutputStream requestBody = connection.getOutputStream();
...
requestBody.flush();

//send the request and get the response body
InputStream responseBody = connection.getInputStream();
...

Upvotes: 0

Mikita Belahlazau
Mikita Belahlazau

Reputation: 15434

Try apache HttpClient library. It supports https.

Upvotes: 2

Related Questions