关于httpUrlConnection的getOutputStream()异常

qq_34634962 2016-08-03 05:54:16
String url = " http://10.0.0.31:6070/service/XChangeServlet?account=anxin&groupcode=anxin";
URL reslUrl = new URL(url);
HttpURLConnection connection = (HttpURLConnection) reslUrl.openConnection();
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setUseCaches(false);
connection.setRequestProperty("Content-type", "text/xml");
connection.setRequestMethod("POST");
connection.connect();
// 打印状态码
System.out.println(connection.getResponseCode());
File file = new File(strFilePath);
这里就出错了
BufferedOutputStream out = new BufferedOutputStream(connection.getOutputStream());
BufferedInputStream input = new BufferedInputStream(new FileInputStream(file));
int length;
byte[] buffer = new byte[1000];
while ((length = input.read(buffer, 0, 1000)) != -1) {
out.write(buffer, 0, length);
}
input.close();
out.close();



java.net.ProtocolException: Cannot write output after reading input.
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1087)
at com.isoftstone.iis.quartz.VoucherSendQuartzJob.getVoucherXml(VoucherSendQuartzJob.java:66)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.springframework.util.MethodInvoker.invoke(MethodInvoker.java:273)
at org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean$MethodInvokingJob.executeInternal(MethodInvokingJobDetailFactoryBean.java:264)
at org.springframework.scheduling.quartz.QuartzJobBean.execute(QuartzJobBean.java:86)
at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:529)
...全文
826 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
qq_34634962 2016-08-03
  • 打赏
  • 举报
回复
有人吗,急求啊
qq_34634962 2016-08-03
  • 打赏
  • 举报
回复
求解决啊BufferedOutputStream out = new BufferedOutputStream(connection.getOutputStream());这行一直报异常啊

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧