302找到的文档已移动错误 [英] 302 Found Document has Moved error

查看:64
本文介绍了302找到的文档已移动错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在阅读了来自stackoverflow的各种文章以及其他人的一些帮助之后,我在代码中进行了身份验证,并且还尝试避免以前发生的重定向,因为我是所有这些事物的新手.我开始收到与302 Found相同的错误,文档已移动.

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 I am new to all these things. I started getting the same error back of 302 Found, document has moved.

我试图通过在jsp中编写一些代理代码来从我的计算机在本地对其他域进行ajax调用.这是我的jQuery AJAX代码,正在调用proxy.jsp页面.

I am trying to make a ajax call to other domain locally from my computer by writing some proxy code in jsp. And this is my jQuery AJAX code that is calling proxy.jsp page.

    var search_agile_metadata = 'https://search.xyz.com/ag/se/ag/get?id=';

var on_show_info = function() {
                //alert("aa");
    var outOfDomainAjaxCall = search_agile + current_doc_info.id;//An XML document
    alert(outOfDomainAjaxCall);
                request_meta_info = $.ajax({
                url: "proxy.jsp?url=" + outOfDomainAjaxCall,
                type: 'GET',
                success: on_get_metadata,
                error: on_get_metadata_agile

        });

我的proxy.jsp文件是:-

And my proxy.jsp file is:-

    <%@ page language="java" import="org.apache.http.impl.client.AbstractHttpClient,
org.apache.http.client.methods.HttpUriRequest,
org.apache.http.client.methods.HttpGet,
org.apache.http.protocol.HttpContext,
org.apache.http.impl.client.DefaultHttpClient,
org.apache.http.HttpResponse
,org.apache.http.HttpRequest,
java.net.HttpURLConnection,
java.net.URL,
java.util.Collection,
org.apache.commons.httpclient.HttpClient,
org.w3c.dom.*,
javax.xml.parsers.DocumentBuilder,
javax.xml.parsers.DocumentBuilderFactory,
java.net.*,
java.io.*,
org.apache.http.protocol.BasicHttpContext,
org.apache.http.params.BasicHttpParams,
org.apache.http.params.HttpParams,
org.apache.http.Header,
org.apache.http.client.params.HttpClientParams"
contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>

<%
String a_Url = request.getParameter( "url" ) ;

URL url = new URL (a_Url);
String encoding = new String(
         org.apache.commons.codec.binary.Base64.encodeBase64   
            (org.apache.commons.codec.binary.StringUtils.getBytesUtf8("test:test"))
          );


HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.setDoOutput(true);
connection.setFollowRedirects(false);
connection.setRequestProperty  ("Authorization", "Basic " + encoding);
InputStream content = (InputStream)connection.getInputStream();
BufferedReader in   = 
    new BufferedReader (new InputStreamReader (content));
String line;
while ((line = in.readLine()) != null) {
   out.println(line);
}

%>

<%
final HttpParams params = new BasicHttpParams();
HttpClientParams.setRedirecting(params, false);
%>

当我从服务器获得响应时.我得到这个错误.知道为什么我会再次出现此错误..

And when I get the response back from the server. I get this error. Any idea why I am getting this error back..

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>302 Found</title>
</head><body>
<h1>Found</h1>
<p>The document has moved <a href="https://ln.xyz.com/site/n/13000/smscc?TYPE=16777217&amp;R">here</a>.</p>
<hr>
<address>Apache/2.0.58 (Unix) DAV/2 mod_jk/1.2.28 Server at search.xyz.com Port 80</address>
</body></html>

任何帮助将不胜感激.

推荐答案

那不是错误.这是一个非正式的信息.该请求刚刚被重定向.这是一个3nn的响应.只有HTTP 4nn和5nn响应是错误(4nn =客户端错误和5nn =服务器错误)

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)

您的具体问题是,您已通过以下设置告诉HttpURLConnection 遵循重定向:

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);


无关:该问题:请注意,您在此处未完全利用Apache HttpClient API.您仅使用标准的Java SE URLConnection API进行HTTP连接.线


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);

完全不影响URLConnection行为.您应该选择使用其中一个.标准URLConnection API Apache HttpClient.

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

还请记住,在JSP文件而不是Java类中编写Java代码是一种不好的做法.您应该为此工作使用servlet.

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.

这篇关于302找到的文档已移动错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆