【发布时间】:2015-09-01 00:43:51
【问题描述】:
如果我想使用HttpsURLConnection 发送请求。
我可以更改标题中的“remote_addr”吗? (如果我不想得到response,只想将request 发送到服务器)
【问题讨论】:
标签: java
如果我想使用HttpsURLConnection 发送请求。
我可以更改标题中的“remote_addr”吗? (如果我不想得到response,只想将request 发送到服务器)
【问题讨论】:
标签: java
当然可以:
URL myURL = new URL("theURLToRequestTo");
HttpURLConnection myURLConnection = (HttpURLConnection)myURL.openConnection();
myURLConnection.setRequestProperty("REMOTE_ADDR", myIPAddress); // Here you can put the IP you want
myURLConnection.setRequestMethod("GET"); // Or POST as needed
myURLConnection.setRequestProperty("CONTENT-TYPE", "application/x-www-form-urlencoded");
myURLConnection.setRequestProperty("CONTENT-LENGTH", "" + Integer.toString(postData.getBytes().length));
myURLConnection.setRequestProperty("CONTENT-LANGUAGE", "en-US");
myURLConnection.setUseCaches(false);
myURLConnection.setDoInput(true);
myURLConnection.setDoOutput(true);
更新
看this解决方案。
【讨论】: