java服务器返回错误码,java - java.io.IOException:服务器返回URL的HTTP响应代码:409 - 堆栈内存溢出...

我正在使用某些应用程序的API下载文档。 问题是,当我尝试解析inputStream时,它将引发响应代码409异常。 但是最大的问题是它有时会抛出此异常。 此异常的原因是什么?

这是我的代码;

URL url = new URL(urlStr);

HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();

conn.setReadTimeout(10000);

conn.setConnectTimeout(15000);

conn.setRequestMethod("GET");

conn.setDoOutput(true);

conn.setDoInput(true);

conn.setUseCaches(false);

conn.setAllowUserInteraction(false);

if (conn != null) {

try {

InputStream inputStream = conn.getInputStream();//this line throws exception

MyXmlParser myXmlParser = new MyXmlParser();

MyClientData myClientData = myXmlParser.parseMyOutput(inputStream);

return myClientData;

} catch (IOException e) {

throw e;

}

}

这是我的XML解析器;

public class MyXmlParser {

private final JAXBContext myOutputContext;

private final XMLInputFactory xif;

public MyXmlParser() throws JAXBException {

xif = XMLInputFactory.newFactory();

xif.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false);

xif.setProperty(XMLInputFactory.SUPPORT_DTD, false);

myOutputContext = JAXBContext.newInstance(MyClientData.class);

}

public MyClientData parseMyOutput(InputStream inputStream) throws JAXBException {

Unmarshaller jaxbUnmarshaller = myOutputContext.createUnmarshaller();

return (MyClientData) jaxbUnmarshaller.unmarshal(createStreamReader(inputStream));

}

private XMLStreamReader createStreamReader(InputStream inputStream) throws JAXBException {

try {

return xif.createXMLStreamReader(inputStream);

} catch (XMLStreamException ex) {

throw new JAXBException(ex);

}

}

}

这是从应用程序的API中获取的,用于下载文档;

HTTP Request GET /{file_id}/download

我遇到错误了;

java.io.IOException: Server returned HTTP response code: 409 for URL: https://5.5.5.5:443/4144444/download

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值