怎么处理andriod的http衔接需求花费2秒的问题sohu - 凯发娱乐

怎么处理andriod的http衔接需求花费2秒的问题sohu

2019-02-11 08:25:59 | 作者: 元蝶 | 标签: 花费,协议,代码 | 浏览: 5809

// Create a new HttpClient and Post Header HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost("https://192.168.1.137:8880/form"); try { List NameValuePair nameValuePairs = new ArrayList NameValuePair nameValuePairs.add(new BasicNameValuePair("id", "12345")); nameValuePairs.add(new BasicNameValuePair("stringdata", "AndDev is Cool!")); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); // Execute HTTP Post Request HttpResponse response = httpclient.execute(httppost); } catch (ClientProtocolException e) { Log.e(TAG,e.toString()); } catch (IOException e) { Log.e(TAG,e.toString()); }

 

经过以上的代码,翻开一个http衔接,花费了最少2秒钟,不知道为什么?正常的拜访的话,只需求80ms就能够了,考虑下,选用HTTP1.1协议

HttpParams params = new BasicHttpParams();
params.setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
HttpClient httpclient = new DefaultHttpClient(params);

 

If I remember correctly, HTTP 1.0 opens a new TCP connection for every request. Does that explain the large delay?

假如我记住不错的话,http1.0协议为每个恳求树立衔接,这个或许能够解说为什么有这么长的推迟,

A HTTP POST request now takes between 50 and 150 ms over WLAN and something between 300 and 500 ms over 3G.

一般的话,一个post恳求假如经过wlan网络恳求的话大约需求花费50-150ms,假如经过3g或许需求300-500ms;

版权声明
本文来源于网络,版权归原作者所有,其内容与观点不代表凯发娱乐立场。转载文章仅为传播更有价值的信息,如采编人员采编有误或者版权原因,请与我们联系,我们核实后立即修改或删除。

猜您喜欢的文章

阅读排行

  • 1
  • 2
  • 3

    rails 对 URL的一些处理sina

    办法,途径,地址
  • 4
  • 5
  • 6

    Obsolete特点sohu

    特点,正告,运用
  • 7
  • 8

    JAVA根底 之 JDBCITeyetengxun

    数据库,根底,运用
  • 9
  • 10