此代码返回301,而同一脚本正常工作时永久移动

问题描述 投票:0回答:1

这是Java脚本的一部分,用于从网站(https://web.expasy.org/protparam/)收集.xls文件中的某些数据。该网站有一个盒子,我们在其中放置一些字符,然后计算并重定向到另一个URL(https://web.expasy.org/cgi-bin/protparam/protparam)。整个Java脚本运行正常,但一段时间后仍无法正常工作,我试图诊断问题,现在在控制台上收到错误消息

""<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>301 Moved Permanently</title>
</head><body>
<h1>Moved Permanently</h1>
<p>The document has moved <a href="https://web.expasy.org/cgi-bin/protparam/protparam">here</a>.</p>
</body></html>"

有人可以解决这个问题吗?我必须声明一件事:我不是核心编程领域的人,因此我需要您的帮助。

//initializing the url 
URL siturl = new URL("http://web.expasy.org/cgi-bin/protparam/protparam");
//opening the siturl connection
HttpURLConnection conn = null;
conn = (HttpURLConnection)siturl.openConnection();
conn.setRequestMethod("POST");
conn.setFollowRedirects(true);
conn.setRequestProperty("Content-length", String.valueOf(data.length())); 
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
conn.setDoOutput(true);
conn.setDoInput(true);
//setting the output condition to true for printing the contents
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
// used to convert character to bytes
wr.write(data);
//System.out.println(data);
wr.flush();
wr.close();
// Get the response
BufferedWriter out = new BufferedWriter(new FileWriter("xlsresult.xls",true));
// printing the results to a text file
//out.write(data);            
out.write(profilename+ "\t");
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;
javascript java http http-status-code-301
1个回答
0
投票

您正在以HTTP打开连接,但是该页面现在是HTTPS,因此向您发送HTTP 301(因为它现在位于https://web.expasy.org/cgi-bin/protparam/protparam而不是http://web.expasy.org/cgi-bin/protparam/protparam上)。至少那是我的猜测(我对HTTP的使用不多)。

© www.soinside.com 2019 - 2024. All rights reserved.