How to stop NodeJS “Request” module changes request when using proxy

后端 未结 4 1964
小鲜肉
小鲜肉 2021-02-19 22:49

Sorry if this comes off as confusing.

I have written a script using the NodeJS request module that runs and performs a function on a website then returns with the data.

4条回答
  •  孤独总比滥情好
    2021-02-19 23:07

    You're using the http-scheme for you request, but if the webserver redirects http to https and if the proxy-server is not configured to accept redirects (to https) then the problem might only be about the scheme respectively the URL you enter.

    So the proxy had to be configured to accept redirects or the URL has to be checked manually in the case of faults and then adjusted in the case of a redirect.

    Here you can read about redirects on one proxy-server (Apache Traffic Server), the scenario there includes more redirects than I described above:
    https://docs.trafficserver.apache.org/en/4.2.x/admin/reverse-proxy-http-redirects.en.html#handling-origin-server-redirect-responses

    If you still encounter problems the server-logs of the proxy-server would be helpful.

    EDIT:
    According to he page @Jannes Botis linked there exist still more proxy-settings that might be able to support or disrupt the desired functionality, so the whole issue is perhaps about configuring the proxy-server correct. Here are a few settings that are directly related to redirects:

    followRedirect - follow HTTP 3xx responses as redirects (default: true). This property can also be implemented as function which gets response object as a single argument and should return true if redirects should continue or false otherwise.
    followAllRedirects - follow non-GET HTTP 3xx responses as redirects (default: false)
    followOriginalHttpMethod - by default we redirect to HTTP method GET. you can enable this property to redirect to the original HTTP method (default: false)
    maxRedirects - the maximum number of redirects to follow (default: 10)
    removeRefererHeader - removes the referer header when a redirect happens (default: false). Note: if true, referer header set in the initial request is preserved during redirect chain.
    

    It's quite possible that other settings of the proxy-server have impact on fail or success of your scenario too.

提交回复
热议问题