Runnable runnable = new Runnable() {
@Override
public void run() {
HttpURLConnection conn = null;
InputStream inputStream = null;
try {
URL url = new URL(baseUrl);
conn = (HttpURLConnection)url.openConnection();
conn.setConnectTimeout(10000);
conn.setReadTimeout(8000);
conn.setDoInput(true);
conn.setRequestMethod("GET");
conn.setRequestProperty("Content-Type", "text/html");
conn.setRequestProperty("Accept-Charset", "utf-8");
conn.setRequestProperty("contentType", "utf-8");
inputStream = conn.getInputStream();
byte[] buffer = null;
if(conn.getResponseCode() == 200){
buffer = new byte[1024];
ByteArrayOutputStream out = new ByteArrayOutputStream();
int len;
while ((len = inputStream.read(buffer)) != -1)
{
out.write(buffer, 0, len);
}
buffer = out.toByteArray();
}
mCallback.HandleAsync(buffer);
SendMsg("value",buffer);
} catch (Exception e) {
e.printStackTrace();
Log.e("sjr","Network-error");
}
finally{
try {
if(inputStream != null){
inputStream.close();
}
if(conn != null){
conn.disconnect();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
};
private Runnable runnable = new Runnable() {
@Override
public void run() {
String url = BaseServicesInfo.SERVER_BASE_PATH + fileName;
HttpPost httpRequest = new HttpPost(url);
try{
HttpEntity entity = new UrlEncodedFormEntity(params);
httpRequest.setEntity(entity);
HttpClient client = new DefaultHttpClient();
// /* 请求超时 */
client.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 20000);
// /* 读取超时 */
client.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, 20000 );
HttpResponse response = client.execute(httpRequest);
if(response.getStatusLine().getStatusCode() == 200){
str = EntityUtils.toString(response.getEntity());
Message msg = new Message();
Bundle data = new Bundle();
data.putString("value", str);
msg.setData(data);
handler.sendMessage(msg);
}else{
str = String.valueOf(response.getStatusLine().getStatusCode());
Message msg = new Message();
Bundle data = new Bundle();
data.putString("error", str);
msg.setData(data);
handler.sendMessage(msg);
}
}catch(Exception e){
e.printStackTrace();
Message msg = new Message();
Bundle data = new Bundle();
data.putString("error", str);
msg.setData(data);
handler.sendMessage(msg);
}
}
};
分享到:
相关推荐
11.1.2 将HttpClient用于HTTPPOST请求(多部分POST请求示例) 11.1.3 SOAP、JSON和XML分析程序 11.1.4 处理异常 11.1.5 解决多线程问题 11.1.6 有趣的超时 11.1.7 使用HttpURLConnection 11.1.8 ...
AndroidInject 是 Android 注解框架,以简化 Android 开发 目前完成的注解(持续增加中): @AINoTitle: 类注解, 只适用于Activity(需继承于AIActivity), 设置Activity不显示Title @AIFullScreen: 类注解...
11.1.2 将HttpClient用于HTTPPOST请求(多部分POST请求示例) 11.1.3 SOAP、JSON和XML分析程序 11.1.4 处理异常 11.1.5 解决多线程问题 11.1.6 有趣的超时 11.1.7 使用HttpURLConnection 11.1.8 ...
功能支持HTTP GET / POST / PUT / DELETE / HEAD / PATCH支持同步和异步请求通过进度下载文件从url中以位图的形式获取图像MultiPart Upload响应磁盘中的缓存OkHttp缓存控件的完全支持支持OkHttp并具有编写自己的...
24、httpget与post 38 Handler+Runnable模式 40 Handler+Thread+Message模式 42 Handler+ExecutorService(线程池)+MessageQueue模式 44 Handler+ExecutorService(线程池)+MessageQueue+缓存模式 45 25、Bitmap操作 ...
◦ 方法(GET、HEAD、POST、PUT、DELETE、PATCH) ◦ 标头 ◦ Cookie ◦ 最大重定向计数 ◦ 超时 - 访问服务器发送的每个比特位: ◦ 标头 ◦ 状态代码 ◦ Cookie ◦ 原始内容 ◦ 尾部标头 - 连接和内存池 - 连接和...
public void configTimeout(int timeout)//配置超时时间 public void configSSLSocketFactory(SSLSocketFactory sslSocketFactory) //配置https请求 public void configRequestExecutionRetryCount(int count)//...
QSHttp开箱即用,GET,POST,表单,JSON,上传,下载等等统统同一行代码搞定!AIP精简到极致,调用没有一行多余代码,几乎零成本使用,大道至简5年实战环境验证迭代,稳定可靠强大灵活的入参,支持泛型回调,使用简单可简单实现...
*网络:飞行模式(或根用户),自动同步,BT,BT ID,撰写电子邮件,浏览URL,HTTP GET,HTTP POST,移动数据(开/关),移动数据2G / 3G(仅Cyanogen),USB系绳,WiFi切换,Wifi断开/重新关联/重新连接,Wifi睡眠...
*网络:飞行模式(或root),自动同步,BT,BT ID,撰写电子邮件,浏览URL,HTTP GET,HTTP POST,移动数据(开/关),移动数据2G / 3G(仅限氰化物,USB系绳,WiFi切换,Wifi断开/重新连接/重新连接,Wifi睡眠,...
2、支持restful风格api接口请求,支持get、post、put、delete、head、patch、head请求方式; 3、请求数据格式支持Form表单格式、MultiPart多请求体格式、Json请求体格式; 4、支持文件断点下载、下载进度监听、文件...
[ 3.175402] Bluetooth: get rtl8723bs rtl8723bs_bt_host_wake gpio failed [ 3.953017] Bluetooth: RFCOMM TTY layer initialized [ 3.958456] Bluetooth: RFCOMM socket layer initialized [ 3.964183] ...
[ 3.175402] Bluetooth: get rtl8723bs rtl8723bs_bt_host_wake gpio failed [ 3.953017] Bluetooth: RFCOMM TTY layer initialized [ 3.958456] Bluetooth: RFCOMM socket layer initialized [ 3.964183] ...