Android Sporadic 401身份验证所需的错误

时间:2014-01-03 19:47:23

标签: android httprequest http-status-code-401

在调用我的一个托管有hostgator的php web服务时,我看到了奇怪的行为。有时我会收到来自我服务的401未经授权的回复。其他时候它工作正常。真奇怪的是,如果我从Android获得401,然后我从笔记本电脑浏览器调用该服务,它将在Android上重新开始工作。关于从我的笔记本电脑上的浏览器调用服务的事情“重置”它,以便我在Android上暂时不会获得401。

new AsyncTask<Void, Void, String>() {
    @Override
    protected String doInBackground(Void... params) {

        HttpClient httpClient = new DefaultHttpClient();
        HttpPost httpPost = new HttpPost("http://myurl.com/myscript.php");
        try {
            HttpResponse response = httpClient.execute(httpPost);
            final String str = EntityUtils.toString(response.getEntity());
            Log.d(TAG, str);
        }
        catch (IOException e) {
            e.printStackTrace();
        }

        return "";
    }

    @Override
    protected void onPostExecute(String msg) {
        Log.d(TAG, "post executed");
    }

}.execute(null, null, null);

0 个答案:

没有答案