POST到HTTPS服务

时间:2012-05-31 17:27:46

标签: java post https

我需要知道如何POSTHTTPS网络服务。我经历了tutorial,但它没有帮助,因为它太旧了。

有人可以通过给我一个好的教程或一些示例代码来帮助我吗?

2 个答案:

答案 0 :(得分:2)

尝试使用apache HttpClient库。它支持https

答案 1 :(得分:0)

这样的事情:

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();
...