文档移动错误

发布于 2024-11-18 02:03:22 字数 3004 浏览 2 评论 0原文

在阅读了 stackoverflow 上的各种帖子以及其他人的一些帮助后,我在代码中进行了身份验证,并试图避免之前发生的重定向,因为我对所有这些事情都是新手。我开始收到相同的错误 302 Found,文档已移动。

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

var search_agile_metadata = 'https://doc.xyz.com/rest-services/services/get?id=';

var on_show_info = function() {
var outOfDomainCall = search_agile_metadata + current_doc.id;//An XML document

request_meta_info = $.ajax({
url: "proxy.jsp?url=" + outOfDomainCall,
                type: 'GET',
                success: on_get_metadata,
                error: on_get_metadata_error

        });

我的 proxy.jsp 文件是:-

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

当我从服务器收到响应时。我收到这个错误。知道为什么我会收到此错误。

    <!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://login.xyz.com/siteminder/cert/13890/smgetcred.scc?TYPE=16777217&amp;REALM=-SM-amp;SMAUTHREASON=0&amp;METHOD=GET&amp;SMAGENTNAME=-SM-3FfhzbcpbcT6grIIICnrPzvFIbogCZlcnVHG8&amp;TARGET</p>
<hr>
<address>Apache/2.0.58 (Unix) DAV/2 mod_jk/1.2.28 Server at doc.xyz.com Port 80</address>
</body></html>

任何帮助将不胜感激。

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.

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://doc.xyz.com/rest-services/services/get?id=';

var on_show_info = function() {
var outOfDomainCall = search_agile_metadata + current_doc.id;//An XML document

request_meta_info = $.ajax({
url: "proxy.jsp?url=" + outOfDomainCall,
                type: 'GET',
                success: on_get_metadata,
                error: on_get_metadata_error

        });

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://login.xyz.com/siteminder/cert/13890/smgetcred.scc?TYPE=16777217&REALM=-SM-amp;SMAUTHREASON=0&METHOD=GET&SMAGENTNAME=-SM-3FfhzbcpbcT6grIIICnrPzvFIbogCZlcnVHG8&TARGET</p>
<hr>
<address>Apache/2.0.58 (Unix) DAV/2 mod_jk/1.2.28 Server at doc.xyz.com Port 80</address>
</body></html>

Any help will be appreciated..

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦开始←不甜 2024-11-25 02:03:22

我不认为 HTTPS 让你这么麻烦,但 401 Unauthorized 才是关键。检查协议内容: http://www.w3.org /Protocols/rfc2616/rfc2616-sec10.html#sec10.4.2 。您的请求在某种程度上需要考虑授权标头。我过去曾使用 HttpClient 库完成此操作:http://hc。 apache.org/httpclient-3.x/authentication.html

I don't think it is HTTPS that is messing you up so much, but the 401 Unauthorized is the key. Check what the protocol says: http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.2 . Your request somehow needs to account for an Authorization header. I've done this in the past with the HttpClient library: http://hc.apache.org/httpclient-3.x/authentication.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文