sotimeout不是在一个多HTTP POST工作在Android 2.1 [英] sotimeout not working in a multipart http post on android 2.1

查看:118
本文介绍了sotimeout不是在一个多HTTP POST工作在Android 2.1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Apache的HttpClient附带的Andr​​oid SDK中上传关于使用多HTTP POST服务器的文件。问题是,当我关掉我的设备上的WiFi连接和设备具有设置sotimeout后无法上网和事件,并connectiontimeout的code挂在 httpclient.execute()语句无限期它发生每一次。

我的code是:

 的HttpClient HttpClient的=新DefaultHttpClient();HttpConnectionParams.setSoTimeout(httpclient.getParams(),5000);
ConnManagerParams.setTimeout(httpclient.getParams(),5000);HttpConnectionParams.setSocketBufferSize(httpclient.getParams(),8192);HttpPost(HTTP:// myurl);档案文件=新的文件(fileAbsolutePath);
MultipartEntity mpEntity =新MultipartEntity();
ContentBody cbFile =新FileBody(文件);
mpEntity.addPart(UploadedFile的cbFile);
httppost.setEntity(mpEntity);
如果(!backupCancel)
{
    System.out.println(\"<<<<<<<<<<<<<<<<<<<<<<Actually传送文件&gt;&GT;&GT;&GT;&GT;&GT;&GT;&GT;&GT;&GT;&GT;&GT;&GT;&GT;&gt;中);
    HTT presponse响应= httpclient.execute(httppost);
}


解决方案

试试这个:

假设u有一个HttpClient的对象,它是AndroidHttpClient或DefaultHttpClient的实例

 的HttpParams的HttpParams = httpClient.getParams();
httpParams.setIntParameter(CoreConnectionPNames.SO_TIMEOUT,以毫秒秒超时);

的HttpParams你得到的是使其在执行setIntParameter将解决这一问题的参考对象。

除非你真正有特殊要求定制使用AndroidHttpClient它是非常有用和最解决了我们的问题:)好运气超时preFER

I am using the apache httpclient that ships with the android sdk to upload a file on server using multipart http post. The problem is that when i turn off the wifi connection on my device and the device has no internet access and event after setting the sotimeout and connectiontimeout the code hangs on the httpclient.execute() statement indefinitely and it happens every single time.

my code is:

HttpClient httpclient = new DefaultHttpClient();

HttpConnectionParams.setSoTimeout(httpclient.getParams(), 5000);
ConnManagerParams.setTimeout( httpclient.getParams(), 5000 ); 

HttpConnectionParams.setSocketBufferSize(httpclient.getParams(), 8192);

HttpPost("http://myurl");

File file = new File(fileAbsolutePath);
MultipartEntity mpEntity = new MultipartEntity();
ContentBody cbFile = new FileBody(file);
mpEntity.addPart("uploadedfile", cbFile);
httppost.setEntity(mpEntity);
if(!backupCancel)
{
    System.out.println("<<<<<<<<<<<<<<<<<<<<<<Actually transferring file>>>>>>>>>>>>>>>");
    HttpResponse response = httpclient.execute(httppost);
}

解决方案

Try this:

Assuming u have a httpClient object which is a instance of AndroidHttpClient or DefaultHttpClient

HttpParams httpParams = httpClient.getParams();
httpParams.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, Timeout in milli seconds);

httpParams you get is a reference object so it executing setIntParameter will fix the issue

Unless you real have a special requirement for custom timeouts prefer using AndroidHttpClient it is very useful and solves most of our problems :) good luck

这篇关于sotimeout不是在一个多HTTP POST工作在Android 2.1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆