【问题标题】:Can I Change "remote_addr" in my request我可以在我的请求中更改“remote_addr”吗
【发布时间】:2015-09-01 00:43:51
【问题描述】:

如果我想使用HttpsURLConnection 发送请求。 我可以更改标题中的“remote_addr”吗? (如果我不想得到response,只想将request 发送到服务器)

【问题讨论】:

    标签: java


    【解决方案1】:

    当然可以:

        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解决方案。

    【讨论】:

    • 但是服务器在 "REMOTE_ADDR" 中得到了我的真实 ip,而不是我在 header 中输入的 ip。
    猜你喜欢
    • 2023-03-08
    • 2016-10-13
    • 1970-01-01
    • 1970-01-01
    • 2021-05-27
    • 2016-07-28
    • 2016-06-11
    • 2010-09-28
    相关资源
    最近更新 更多