mHttpClient.execute(httppost)具有极长的响应3G / 4G ..但不是无线网络。 ICS更新后 [英] mHttpClient.execute(httppost) with extremely long response 3g/4g.. but NOT wifi. after ICS update

查看:467
本文介绍了mHttpClient.execute(httppost)具有极长的响应3G / 4G ..但不是无线网络。 ICS更新后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不能让这一个。有一个应用程序,是伟大的工作。然后,我更新了我的Razr手机Droid的ICS的,事情发生了变化。

I can't get this one. Had an app that was working great. Then I updated my Razr Droid to ICS and things have changed.

运行Drupal的服务器使用Drupal服务模块。当我连接通过WiFi,一切都很正常。当我不过连接通过3G / 4G的httpclient.execute()方法需要3-4分钟,而不是秒。我放在一起下面的示例code这再现了问题。我要补充一点,浏览器连接到服务器超过4G正常工作。所以我不认为这是一个简单的无线连接问题。

Running a Drupal Server with Drupal Services Module. When I connect over wifi, everything works great. When I connect over 3g/4g however, the httpclient.execute() method takes 3-4 minutes instead of seconds. I put together the following sample code which recreates the problem. I should add that browser connection to the server over 4g works fine.. So I don't think this is a simple wireless connection issue.

public class DrupalTestActivity extends Activity {


    private Context mCtx;
public static long mSESSION_LIFETIME = 200000; // seconds.
final static String URL =   "www.myDrupalServer.com";
final static String ENDPOINT = "rest/";
String mResponse = null;
String cookie;
TextView textView;

public class DoLogin extends AsyncTask<Void, Void, String> {

    @Override
    protected String doInBackground(Void... params) {
        cookie = getCookie(mCtx);
        return cookie;
    }

    @Override
    protected void onPostExecute(String result) {
        super.onPostExecute(result);
        textView.setText(mResponse);
    }



}

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.mCtx = this;
    setContentView(R.layout.main);
    textView = (TextView) findViewById(R.id.textView);
    DoLogin task = new DoLogin();
    task.execute();
}


protected String getCookie(Context ctx) {
    SharedPreferences settings = PreferenceManager
            .getDefaultSharedPreferences(mCtx);
    Long timestamp = settings.getLong("sessionid_timestamp", 0);
    Long currenttime = new Date().getTime() / 100;
    String cookie = settings.getString("cookie", null);
    if (cookie == null || (currenttime - timestamp) >= mSESSION_LIFETIME) {
        JSONObject mUserAccount = UserAccount.getJSONUserAccount(ctx);
        userLogin(mUserAccount);
        return getCookie(ctx);
    } else {
        Log.d("COOKIE", cookie);
        return cookie;
    }
}


public String userLogin(JSONObject mUserAccount) {
    String uri = URL + ENDPOINT + "user/login";
    HttpPost httppost = new HttpPost(uri);
    httppost.setHeader("Content-type", "application/json");
    StringEntity se;
    try {
        HttpClient mHttpClient = new DefaultHttpClient();
        HttpParams mHttpParams = new BasicHttpParams();
        HttpConnectionParams.setConnectionTimeout(mHttpParams, 10000);
        HttpConnectionParams.setSoTimeout(mHttpParams, 10000);

        se = new StringEntity(mUserAccount.toString());
        se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE,
                "application/json"));
        httppost.setEntity(se);
                    Log.d("STATUS", "CALLING DRUPAL");
        HttpResponse response = mHttpClient.execute(httppost);
                    Log.d("STATUS", "LOGIN COMPLETE");
        mResponse = EntityUtils.toString(response.getEntity());
        // save the sessid and session_name
        JSONObject obj = new JSONObject(mResponse);
        SharedPreferences settings = PreferenceManager
                .getDefaultSharedPreferences(mCtx);
        SharedPreferences.Editor editor = settings.edit();
        editor.putString("cookie", obj.getString("session_name") + "="
                + obj.getString("sessid"));
        editor.putLong("sessionid_timestamp",
                new Date().getTime() / 100);
        editor.commit();
    } catch (UnsupportedEncodingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return mResponse;
    }
}

下面是类UserAccount,但我真的不认为这是相关的。

Here is class UserAccount, but I don't really think it's relevant..

public class UserAccount {

    private String USER = "tester";
    private String PASSWORD = "passtest";
    private static Context mCtx;

    public UserAccount(Context Ctx, String Username, String Password) {
        mCtx = Ctx;
    }

    public void save(Context mCtx) {
        // TODO This would really work better if we just passed in the Account
        // Object
        Map<String, String> mMap = new HashMap<String, String>();
        mMap.put("username", USER);
        mMap.put("password", PASSWORD);
        SharedPreferences settings = PreferenceManager
                .getDefaultSharedPreferences(mCtx);
        SharedPreferences.Editor editor = settings.edit();
        Iterator<?> iter = mMap.entrySet().iterator();
        while (iter.hasNext()) {
            @SuppressWarnings("rawtypes")
            Map.Entry mEntry = (Map.Entry) iter.next();
            editor.putString(mEntry.getKey().toString(), mEntry.getValue()
                    .toString());
        }
        editor.commit();
    }



    public static JSONObject getJSONUserAccount(Context ctx) {
        SharedPreferences accountSettings = PreferenceManager
                .getDefaultSharedPreferences(ctx);
        String nUsername = accountSettings.getString("username", "tester");
        String nPassword = accountSettings.getString("password", "dweeber");
        JSONObject JSONUser = new JSONObject();
        try {
            JSONUser.put("password", nPassword);
            JSONUser.put("username", nUsername);
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        return JSONUser;
    }

}

LogCat中输出,W​​iFi连接。

LogCat output for the wifi connection.

07-02 16:49:32.812: I/System.out(12001): debugger has settled (1401)
07-02 16:49:33.319: D/dalvikvm(12001): threadid=1: still suspended after undo (sc=1 dc=1)
07-02 16:49:36.921: D/STATUS(12001): CALLING DRUPAL
07-02 16:49:37.749: D/libc(12001): Forward DNS query to netd(h=www.seinetest.com.php5-22.dfw1-1.websitetestlink.com s=^)
07-02 16:49:43.046: D/STATUS(12001): LOGIN COMPLETE

时间就是十几秒钟左右。

Time is a dozen seconds or so..

在3G / 4G LogCat中输出

LogCat output on 3g/4g

07-02 16:52:36.171: I/System.out(12759): debugger has settled (1362)
07-02 16:52:36.687: D/dalvikvm(12759): threadid=1: still suspended after undo (sc=1 dc=1)
07-02 16:52:46.171: D/STATUS(12759): CALLING DRUPAL
07-02 16:52:47.265: D/libc(12759): Forward DNS query to netd(h=www.seinetest.com.php5-22.dfw1-1.websitetestlink.com s=^)
07-02 16:53:17.569: W/IInputConnectionWrapper(12759): getExtractedText on inactive InputConnection
07-02 16:53:17.593: W/IInputConnectionWrapper(12759): getExtractedText on inactive InputConnection
07-02 16:54:38.593: W/IInputConnectionWrapper(12759): getExtractedText on inactive InputConnection
07-02 16:54:38.616: W/IInputConnectionWrapper(12759): getExtractedText on inactive InputConnection
07-02 16:56:08.921: D/STATUS(12759): LOGIN COMPLETE

更长的登录时间!!

MUCH longer login time!!

显然,getExtractedText是新的东西,但它是一个原因还是结果?我做了这里IInputConnectionWrapper getExtractedText搜索,并有一个问题如果有人问什么的意义。它被关闭并标记为坏的问题。 :(

Clearly, the getExtractedText is something new,but is it a cause or a result? I did a search on here for IInputConnectionWrapper getExtractedText and there is one question where someone asks what it's significance is.. It was closed and marked as a bad question. :(

欲知更多详情,Verizon的载体 服务器托管在Rackspace的云服务器 手机Verizon的DROID RAZR,安卓4.0.4

Additional details are Verizon carrier Server is hosted on Rackspace Cloud Servers Phone Verizon Droid Razr, Android 4.0.4

我真的希望我能在这里得到一些指导或我几个月的工作都半身像。由于一吨的任何帮助都没有。

I'm really hopeful I can get some guidance here or my months of work are bust. Thanks a ton for any help at all.

推荐答案

我想,我终于想通了这一点。我做了一些研究和一些测试。
手机DROID RAZR,ICS 4.0.4 Verizone无线。

I THINK I finally figured this out. I did some research and some tests.
Phone Droid Razr, ICS 4.0.4 Verizone wireless.

我调查我的三个服务器和谷歌。我的所有测试服务器都位于相同的云(Rackspace公司) 响应时间如下。 谷歌:42ms 我的服务器#1 100毫秒 我的服务器#2 96 我的服务器#3 - 一个测试服务器,没有注册的域名运行的www.seinetest.blah.blah.websitetestlink.com。 Rackspace公司自动执行,直到一个域名被注册到服务器..响应时间14445毫秒。

I polled three of my servers and google. All of my test servers are located on same cloud (RackSpace) Response times were as follows. Google: 42ms My Server #1 100ms My Server #2 96 My Server #3 - A test server with no Domain name registered running as www.seinetest.blah.blah.websitetestlink.com. Rackspace automatically does this until a domain name is registered with the server.. Response time 14445 ms.

桌面浏览器时代到所有四个站点均未见明显异常。所以,问题必须在手机..或做的吗?

Desktop Browser times to all four sites were unremarkable. So the problem HAD to be in the phone.. or did it?

升级到ICS后,这种巨大的差异的响应时间随之而来。我发现在其他手机中有问题,ICS获得通过代理上述链接的一些数据。我叫Rackspace公司和向我保证,我的注册域名服务器和服务器#3之间的唯一区别,是那里的DNS指针分别指向了..没有代理!

After upgrade to ICS, this huge discrepancy in response times cropped up. I did find some data in the above links that other phones were having problems with ICS getting through proxies. I called Rackspace and the assured me the only difference between my registered domain name servers and server #3, was where the DNS pointers were pointing.. no proxies!

留下很少的东西去尝试,我注册服务器#3与域名和WALLAH! 从ICS电话响应时间等于与注册域名的其他服务器..因为这一切发生的ICS升级我倾向于认为这是一个ICS的错误,我会报告。

Leaving very little else to try, I registered server #3 with a domain name and WALLAH! Response times from the ICS phone are equal to the other servers with registered domain names.. given that this all happened with the ICS upgrade I am inclined to think this is an ICS bug which I'll be reporting.

这篇关于mHttpClient.execute(httppost)具有极长的响应3G / 4G ..但不是无线网络。 ICS更新后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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