非标准 HTTP 端口源的 URLConnection FileNotFoundException [英] URLConnection FileNotFoundException for non-standard HTTP port sources
问题描述
我试图使用 Apache Ant Get
任务 获取我们公司另一个团队生成的 WSDL 列表.他们将它们托管在 http://....com:7925/上的 weblogic 9.x 服务器上服务/.我可以通过浏览器访问该页面,但是在尝试将页面复制到本地文件进行解析时,get 任务给了我一个 FileNotFoundException.我仍然能够(使用 ant 任务)获得一个没有非标准 HTTP 端口 80 的 URL.
I was trying to use the Apache Ant Get
task to get a list of WSDLs generated by another team in our company. They have them hosted on a weblogic 9.x server on http://....com:7925/services/. I am able to get to the page through a browser, but the get task gives me a FileNotFoundException when trying to copy the page to a local file to parse. I was still able to get (using the ant task) a URL without the non-standard port 80 for HTTP.
我查看了 Ant 源代码,并将错误范围缩小到 URLConnection.似乎 URLConnection 无法识别数据是 HTTP 流量,因为它不在标准端口上,即使协议被指定为 HTTP.我使用 WireShark 嗅探了流量,页面通过网络正确加载,但仍然收到 FileNotFoundException.
I looked through the Ant source code, and narrowed the error down to the URLConnection. It seems as though the URLConnection doesn't recognize the data is HTTP traffic, since it isn't on the standard port, even though the protocol is specified as HTTP. I sniffed the traffic using WireShark and the page loads correctly across the wire, but still gets the FileNotFoundException.
这是一个示例,您将在其中看到错误(更改了 URL 以保护无辜者).在 connection.getInputStream();
Here's an example where you will see the error (with the URL changed to protect the innocent). The error is thrown on connection.getInputStream();
import java.io.File;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
public class TestGet {
private static URL source;
public static void main(String[] args) {
doGet();
}
public static void doGet() {
try {
source = new URL("http", "test.com", 7925,
"/services/index.html");
URLConnection connection = source.openConnection();
connection.connect();
InputStream is = connection.getInputStream();
} catch (Exception e) {
System.err.println(e.toString());
}
}
}
推荐答案
检查服务器返回的响应码
check the response code being returned by the server
这篇关于非标准 HTTP 端口源的 URLConnection FileNotFoundException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!