1

単純な HTTP リクエストを実装しようとしています。リクエストは、サーバーからのユーザー名とパスワードを検証します。サーバーは、検証済みの 200 とそれ以外のすべての 404 の 2 つのエラー コードのみを返すように構成されています。eclipse で大規模なデバッグを行ったところ、コード 404 を常に受け​​取ることがわかりました。これを投稿する前に、他のすべての既存の質問を読みました。

private class loginTask extends AsyncTask<String, Integer, Boolean> {
    String check;
    @Override
    protected Boolean doInBackground(String... arg0) {
                ("http://www.unite.upmc.edu/account/IPhoneLogin?username=username&password=password

        String username = arg0[0];
        String password = arg0[1];
        URI uri = null;
        try {
            uri = new URI("http://unite.upmc.edu/account/IPhoneLogin?"+"username="+username+"&"+"password="+password);// I know the method is called IPhoneLogin, it's being used by both Android and IOS clients
        } catch (URISyntaxException e1) {

            e1.printStackTrace();
        }
        HttpClient client = new DefaultHttpClient();

        try {//Look here

            HttpResponse response = client.execute(new HttpGet(uri));
            String code = "" + response.getStatusLine().getStatusCode();
            check = code;
            if(code.equals("200")){
                loggedIn = true;
            }else{
                                    //need to re-enter username and password
            }
        } catch (ClientProtocolException e) {

            e.printStackTrace();
        } catch (IOException e) {

            e.printStackTrace();
        }


        hasPin = false;
        return true;
    }

    @Override
    protected void onProgressUpdate(Integer... integers) {
        setProgress(integers[0]);
    }

    @Override
    protected void onPreExecute() {

        ProgressDialog dialog = new ProgressDialog(UniteActivity.this);
        dialog.setMessage("Logging in...." + check);
        dialog.show();

    }

Internet Explorer を使用して通常どおりに何度もログインしたため、サーバーが稼働しており、パスワードとユーザー名が正しいことはわかっています。私は Android SDK で Eclipse IDE を使用していますが、これが提供するバグのあるエミュレーターの製品である可能性があることを懸念しています。私が間違っていることについてのアイデアはありますか?

4

1 に答える 1

0

doInBackground メソッドでこのコードを試して、応答コードを取得します

url = new URL(mUrl);

            Log.i(LOG_TAG, url+"");
            HttpGet method= new HttpGet(new URI(mUrl));
            HttpClient client = new DefaultHttpClient();
            HttpGet request = new HttpGet();
            request.setURI(new URI(mUrl));
            HttpResponse response = client.execute(method);
            responseCode = response.getStatusLine().getStatusCode();

うまくいけば、これはうまくいくでしょう。

于 2013-01-15T06:14:46.180 に答える