java url 403_Java SAX解析器为有效URL引发403异常

SAX解析器为有效URL抛出403异常,该异常在浏览器中加载时没有任何问题。我们能够用下面的示例代码重现问题。指针表示感谢。

import javax.xml.parsers.SAXParser;

import javax.xml.parsers.SAXParserFactory;

import org.xml.sax.helpers.DefaultHandler;

public class StackOverflow {

public static void main(String[] args) {

SAXParserFactory factory2 = SAXParserFactory.newInstance();

try {

String uri;

uri = "https://www.sec.gov/Archives/edgar/data/1326801/000132680119000009/FilingSummary.xml"; // Does not work

// uri = "https://www.w3schools.com/xml/simple.xml"; // ** Works if this line is uncommented **

SAXParser saxParser = factory2.newSAXParser();

DefaultHandler eventHandler = new DefaultHandler();

saxParser.parse(uri, eventHandler);

// ...

// Business Logic

// ...

System.out.println("SUCCESS");

}

catch (Exception e1) {

// TODO Auto-generated catch block

e1.printStackTrace();

}

}

}

stacktrace如下:

java.io.IOException: Server returned HTTP response code: 403 for URL: https://www.sec.gov/Archives/edgar/data/1326801/000132680119000009/FilingSummary.xml

at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(Unknown Source)

at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)

at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(Unknown Source)

at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(Unknown Source)

at com.sun.org.apache.xerces.internal.impl.XMLVersionDetector.determineDocVersion(Unknown Source)

at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)

at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)

at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)

at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source)

at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)

at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl.parse(Unknown Source)

at javax.xml.parsers.SAXParser.parse(Unknown Source)

at StackOverflow.main(StackOverflow.java:15)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值