如果我想使用HttpsURLConnection
发送请求。
我可以在标题中更改“remote_addr
”吗? (如果我不想获得response
,只想将request
发送到服务器
答案 0 :(得分:0)
当然你可以:
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解决方案。