gpt4 book ai didi

java - SAXParser 说 :"java.net.SocketException: Network is unreachable"但 xmlint 或 curl 都可以

转载 作者:行者123 更新时间:2023-11-30 09:51:23 26 4
gpt4 key购买 nike

我可以下载以下 URL:“http://genome.ucsc.edu/cgi-bin/das/hg18/dna?segment=chr1%3A10%2C20”

使用 xmllint :

xmllint "http://genome.ucsc.edu/cgi-bin/das/hg18/dna?segment=chr1%3A10%2C20"
<?xml version="1.0" standalone="no"?>
<!DOCTYPE DASDNA SYSTEM "http://www.biodas.org/dtd/dasdna.dtd">
<DASDNA>
<SEQUENCE id="chr1" start="10" stop="20" version="1.00">
<DNA length="11">
ccctaacccta
</DNA>
</SEQUENCE>
</DASDNA>

curl

curl "http://genome.ucsc.edu/cgi-bin/das/hg18/dna?segment=chr1%3A10%2C20"
<?xml version="1.0" standalone="no"?>
<!DOCTYPE DASDNA SYSTEM "http://www.biodas.org/dtd/dasdna.dtd">
<DASDNA>
<SEQUENCE id="chr1" start="10" stop="20" version="1.00">
<DNA length="11">
ccctaacccta
</DNA>
</SEQUENCE>
</DASDNA>

但是下面的 java 程序引发了异常:

import javax.xml.parsers.*;
public class Test
{
public static void main(String args[])
{
try
{
SAXParserFactory f=SAXParserFactory.newInstance();
f.setNamespaceAware(false);
f.setValidating(false);
f.newSAXParser().parse(
"http://genome.ucsc.edu/cgi-bin/das/hg18/dna?segment=chr1%3A10%2C20",
new org.xml.sax.helpers.DefaultHandler()
);
System.out.println("OK");
}
catch(Exception err)
{
err.printStackTrace();
}
}
}

错误:

java Test
java.net.ConnectException: Connection timed out
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:525)
at java.net.Socket.connect(Socket.java:475)
at sun.net.NetworkClient.doConnect(NetworkClient.java:163)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:394)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:529)
at sun.net.www.http.HttpClient.<init>(HttpClient.java:233)
at sun.net.www.http.HttpClient.New(HttpClient.java:306)
at sun.net.www.http.HttpClient.New(HttpClient.java:323)
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:860)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:801)
at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:726)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1049)
at org.apache.xerces.impl.XMLEntityManager.setupCurrentEntity(Unknown Source)
at org.apache.xerces.impl.XMLEntityManager.startEntity(Unknown Source)
at org.apache.xerces.impl.XMLEntityManager.startDTDEntity(Unknown Source)
at org.apache.xerces.impl.XMLDTDScannerImpl.setInputSource(Unknown Source)
at org.apache.xerces.impl.XMLDocumentScannerImpl$DTDDispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
at javax.xml.parsers.SAXParser.parse(SAXParser.java:395)
at javax.xml.parsers.SAXParser.parse(SAXParser.java:277)
at Test.main(Test.java:11)

为什么?

PS:这里没有代理

最佳答案

(稍后)好的,我得到了答案:SAX 解析器试图加载这个“http://www.biodas.org/dtd/dasdna.dtd”并且这个站点已关闭。

但是我怎样才能阻止 SAX 解析器加载这个 URL???

关于java - SAXParser 说 :"java.net.SocketException: Network is unreachable"但 xmlint 或 curl 都可以,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4684930/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com