- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
上下文:我是一位非常有经验的程序员,但不是一位非常有经验的 Java 程序员。
我继承了一小段代码,用于生成 JNLP 来包装 JAR,以便收集有关客户端计算机的一些信息。在 URL 中未显式指定端口的情况下,这始终工作正常,但在我需要显式指定端口的测试环境中却失败了。
相关的Java代码是:
URL RegURL = new URL(System.getProperty("jnlp.reg"));
...
try {
//Create connection
connection = (HttpURLConnection)RegURL.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
connection.setRequestProperty("Content-Length", "" + Integer.toString(urlParameters.getBytes().length));
connection.setRequestProperty("Content-Language", "en-US");
connection.setUseCaches(false);
connection.setDoInput(true);
connection.setDoOutput(true);
//Send request
DataOutputStream wr = new DataOutputStream (connection.getOutputStream ());
wr.writeBytes (urlParameters);
wr.flush ();
wr.close ();
//Get Response
InputStream is = connection.getInputStream();
...
} catch (Exception e) {
...
} finally {
...
}
RegURL
的值格式为 "http://arthur.OURCOMPANY.com:81/fb/register.php"
,并且我已确认是这样的。但我收到客户端错误:
java.io.FileNotFoundException: http://arthur.OURCOMPANY.com/fb/register.php
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at main.main(main.java:253)
...
这意味着错误是由行 InputStream is = connection.getInputStream();
引发的我认为这意味着端口号在途中的某个地方丢失了,并且它正在使用一个我确实希望无效的 URL。但是,我不知道为什么端口号会丢失。
欢迎任何见解。
最佳答案
如 this answer 中所述您可能需要设置 User-Agent
和 Accept
属性。我的猜测是,如果您使用非标准端口,URLConnection
无法正确猜测您期望接收的内容类型。
关于Java io.FileNotFoundException;有问题的可疑港口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21102073/
Kareltje 需要穿过迷宫 现在我想创建一个 Kareltje 必须找到的坐标列表。这些坐标是端口(墙壁)。当Kareltje走到这个港口时,它会放下一堵墙,这样他就不能回去了。我的问题是我不知道
我已经在 this guide 之后安装了 aurelia-skeleton-navigation| .但是,我想开始使用 Typescript 进行开发。实现这一目标的下一个正确步骤是什么?我想仅仅
我在使用私有(private)和公共(public) udp 端口时遇到了困难。我正在做一个客户端-服务器 VoIP 程序,有一些问题。 1) 私有(private)端口是您在 bind() 中使
我是一名优秀的程序员,十分优秀!