302 Found Document has Moved error

后端 未结 1 1161
囚心锁ツ
囚心锁ツ 2021-01-27 23:33

After reading various post from stackoverflow and some help from other guys I did authentication in my code and also trying to avoid the redirect that was occuring previously as

相关标签:
1条回答
  • 2021-01-28 00:13

    That is not an error. This is an informal message. The request has just been redirected. This is a 3nn response. Only HTTP 4nn and 5nn responses are errors (4nn = client error and 5nn = server error)

    Your concrete problem is that you've told HttpURLConnection to not follow redirects by the following setting:

    connection.setFollowRedirects(false);
    

    So you are seeing the informal message instead of getting automatically redirected to the new request. You should rather have told it to follow redirects:

    connection.setFollowRedirects(true);
    

    Unrelated to the problem: please note that you are not fully utilizing the Apache HttpClient API here. You are just using the standard Java SE URLConnection API to make the HTTP connection. The line

    HttpClientParams.setRedirecting(params, false);
    

    has totally no influence on URLConnection behaviour. You should choose to use the one or the other. Standard URLConnection API or the Apache HttpClient.

    Also please keep in mind that writing Java code in a JSP file instead of a Java class is a poor practice. You should rather be using a servlet for this job.

    0 讨论(0)
提交回复
热议问题