Android OutputStreamWriter's flush method throws IOException
来源:互联网 发布:地区数据库 编辑:程序博客网 时间:2024/06/05 23:58
<span style="white-space: pre;">Android开发弱网络客户端的时候,需要给服务器发送HTTP POST请求,首先进行设置</span>
<span style="white-space: pre;"></span>URL url = new URL(urlString);connection = (HttpURLConnection) url.openConnection();connection.setConnectTimeout(Constants.CONNECTION_TIMEOUT);connection.setReadTimeout(Constants.IO_TIMEOUT);connection.setDoOutput(true);connection.setRequestMethod("POST");connection.setUseCaches(false);connection.setRequestProperty("Content-Type",<span style="white-space: pre;"></span>"application/json:charset=utf-8");connection.setDoInput(true);connection.setDoOutput(true);
<span style="white-space:pre"></span>connection.connect();
<span style="white-space:pre"></span>osw = new OutputStreamWriter(connection.getOutputStream());
<span style="white-space:pre"></span>BufferedReader reader = new BufferedReader(<span style="white-space:pre"></span>new InputStreamReader(conn.getInputStream()));<span style="white-space:pre"></span>//本语句是造成IOException的原因 (1)
然后写入数据
String requestContent = "[" + "{\"ipaddress\":\"" + localIp + "\","+ "\"nettype\":\"" + (netType) + "\"," + "\"envtype\":\""+ envType + "\"}" + "]";osw.write(requestContent);osw.flush();osw.close();报了IOException的错误,此时HTTP的写内容还没完毕,就在代码(1)处开了一个BufferReader,所以造成了IOException。
还有其它人遇到同样的问题,但是原因不一样,请参考
http://stackoverflow.com/questions/4736042/outputstreamwriters-flush-method-throws-ioexception-when-trying-to-write-chines
0 0
- Android OutputStreamWriter's flush method throws IOException
- throws IOException
- Android's HttpURLConnection throws EOFException
- throws IOException的意义
- call method cl_gui_cfw =>flush
- OutputStreamWriter
- OutputStreamWriter
- OutputStreamWriter
- OutputStreamWriter
- android file.createnewfile ioexception
- throws
- Web Method's Attributes
- Ajax's Post Method
- Parallel's foreach method
- Newton's method
- Pollard's Rho Method
- Matlab Newton‘s method
- Muller’s method (website)
- 下载文件通用方法
- 博弈游戏·Nim游戏·二
- 深入剖析微软WPF展示层技术
- 解题报告 之 POJ1021 Fibonacci Again
- 【LeetCode】203.Remove Linked List Elements
- Android OutputStreamWriter's flush method throws IOException
- 用开发者视角看Microsoft Edge
- 交叉线与直通线
- (7.2.4.1)Sql2008 全文索引 简明教程
- [leetcode][array] Remove Duplicates from Sorted Array
- JavaBean,Entity Bean,Enterprise Bean等Bean以及POJO的含义
- AppDelegate的详解
- JavaScript特效实例006-弹出的窗口之Cookie控制
- 浅析 POJ 1852 Ants