java输入错误重新输入无法获取_获取java.net.protocolException:无法在读取输入[重复]后写入输出...

我认为例外不是由于

printing url

. 应该有一些代码试图在读取响应后写入以设置请求主体。

如果您试图获取

HttpURLConnection.getOutputStream()

在获得

HttpURLConnection.getInputStream()

以下是sun.net.www.protocol.http.httpurlconnection.getoutputstream的实现:

public synchronized OutputStream getOutputStream() throws IOException {

try {

if (!doOutput) {

throw new ProtocolException("cannot write to a URLConnection"

+ " if doOutput=false - call setDoOutput(true)");

}

if (method.equals("GET")) {

method = "POST"; // Backward compatibility

}

if (!"POST".equals(method) && !"PUT".equals(method) &&

"http".equals(url.getProtocol())) {

throw new ProtocolException("HTTP method " + method +

" doesn't support output");

}

// if there's already an input stream open, throw an exception

if (inputStream != null) {

throw new ProtocolException("Cannot write output after reading

input.");

}

if (!checkReuseConnection())

connect();

/* REMIND: This exists to fix the HttpsURLConnection subclass.

* Hotjava needs to run on JDK.FCS. Do proper fix in subclass

* for . and remove this.

*/

if (streaming() && strOutputStream == null) {

writeRequests();

}

ps = (PrintStream)http.getOutputStream();

if (streaming()) {

if (strOutputStream == null) {

if (fixedContentLength != -) {

strOutputStream =

new StreamingOutputStream (ps, fixedContentLength);

} else if (chunkLength != -) {

strOutputStream = new StreamingOutputStream(

new ChunkedOutputStream (ps, chunkLength), -);

}

}

return strOutputStream;

} else {

if (poster == null) {

poster = new PosterOutputStream();

}

return poster;

}

} catch (RuntimeException e) {

disconnectInternal();

throw e;

} catch (IOException e) {

disconnectInternal();

throw e;

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值