【问题标题】:mHttpClient.execute(httppost) with extremely long response 3g/4g.. but NOT wifi. after ICS updatemHttpClient.execute(httppost) 具有极长的响应 3g/4g .. 但不是 wifi。 ICS 更新后
【发布时间】:2012-07-07 02:03:41
【问题描述】:

我买不到这个。有一个运行良好的应用程序。然后我将我的 Razr Droid 更新为 ICS,情况发生了变化。

使用 Drupal 服务模块运行 Drupal 服务器。当我通过 wifi 连接时,一切正常。但是,当我通过 3g/4g 连接时,httpclient.execute() 方法需要 3-4 分钟而不是几秒钟。我将以下示例代码放在一起重新创建了问题。我应该通过 4g 添加到服务器的浏览器连接工作正常。所以我认为这不是一个简单的无线连接问题。

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 类,但我认为它并不相关..

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;
    }

}

用于 wifi 连接的 LogCat 输出。

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

时间是十几秒左右..

3g/4g 上的 LogCat 输出

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

更长的登录时间!!

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

其他详细信息是 Verizon 运营商 服务器托管在 Rackspace 云服务器上 电话 Verizon Droid Razr,Android 4.0.4

我真的希望我能在这里得到一些指导,否则我几个月的工作就泡汤了。非常感谢您的帮助。

【问题讨论】:

  • 这是重复出现的9IE。一个星期的每一天)还是你最近才在短时间内测试它(即今天半小时)。我的意思是,你确定这不仅仅是你手机的网络连接吗?会不会是手机信号不好?如果它之前有效而现在无效,并且没有任何更改,这听起来更像是网络问题而不是编码问题。
  • 我确实想过,但是通过手机浏览器通过 3G/4G 连接到服务器效果很好。
  • 另外,还有很多变化。这一切都发生在 ICS 4.0.4 更新之后。这不是一个糟糕的信号问题。此外,我对谷歌 API 的执行调用工作正常。因此,仅在 3g 中,电话和我的服务器之间似乎是一个问题。关于从哪里开始的任何想法?
  • 不幸的是我没有。您的代码看起来不错,而且看起来没有任何问题。您是否在另一台设备上尝试过确定?
  • 不,我没有。我开始怀疑问题是否实际上是 Verizon 的问题。巨大的风暴可能导致我和我的服务器之间的 Verizon 无线出现一些问题。我将给它一周或更长时间,如果它持续存在,我认为下一个问题是与我的主机和 Verizon 取得联系。我应该补充一点,同样的查询对谷歌很有用。所以这不是 ICS 和我的执行方法的问题。我在想它一定是可变的外力。

标签: android


【解决方案1】:

我想我终于想通了。我做了一些研究和一些测试。
Phone Droid Razr,ICS 4.0.4 Verizone 无线。

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

所有四个站点的桌面浏览器使用时间均不显着。所以问题一定出在手机上……还是真的?

升级到 ICS 后,响应时间出现了巨大的差异。我确实在上述链接中发现了一些数据,表明其他手机在 ICS 通过代理时遇到问题。我打电话给 Rackspace,并向我保证我注册的域名服务器和服务器 #3 之间的唯一区别是 DNS 指针指向的位置......没有代理!

几乎没有其他尝试,我用域名和 WALLAH 注册了服务器 #3! ICS 电话的响应时间与注册域名的其他服务器相同。鉴于这一切都发生在 ICS 升级中,我倾向于认为这是我将报告的 ICS 错误。

【讨论】:

    【解决方案2】:

    如果您没有更改任何代码,并且这发生在从 Gingerbread 升级后,您可能真的需要考虑在非 ICS 设备上进行测试。由于 Ice Cream Sandwich 添加了“高效网络使用”功能,因此在 wifi/3G/4G 上出现了一些非常随机的连接问题。您可以在 Google 代码 (http://code.google.com/p/android/issues/list?can=2&q=3g+ics&colspec=ID+Type+Status+Owner+Summary+Stars&cells=tiles) 上看到很多此类问题,并且在这里更切题:http://androidcommunity.com/signal-issues-arrive-after-android-4-0-4-ice-cream-sandwich-update-20120405/ 无论如何,很奇怪,但让人想起我看到的一个无关设备跳转到 ICS 的问题。

    【讨论】:

    • 哦,谢谢你的链接!实际上,我刚刚与 Verizon 通了电话,他们确实说他们在经历中西部的大风暴之后遇到了 3g/4g 问题。也许就是这样,但似乎应该更容易获得一个 JSON 字符串,而不是加载得很好的整个网页。我也无法想象我是唯一一个遇到这个问题的人,但我还没有发现类似的问题。我需要使用非 ICS 电话,并阅读您发布的这些链接。再次感谢您。
    • 我正在做一个很长的测试,看看这是否与网络或 ICS.. 或两者有关?我得到结果后会发布结果。
    • 很好地跟踪您在下面的帖子中介绍的代理问题。没有什么比在机器上钉一个鬼更令人满意的了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-09-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-20
    相关资源
    最近更新 更多