响应代码总是给200

时间:2014-03-31 21:02:19

标签: java android http-post server-response

我想用post方法登录网站......到这里代码是代码,但响应总是给我200 ...我想知道我是否使用正确的用户名和密码成功登录不! ...如果我删除permitAll(),它也会给我networkonmainthreadexception

@TargetApi(Build.VERSION_CODES.GINGERBREAD)
@SuppressLint("NewApi")
private void sendPost()  {

     // Create a new HttpClient and Post Header
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost("https://svuonline.org/isis/login.php?");

    String user=username.getText().toString();
    String pass=password.getText().toString();
    String fpage="/isis/index.php";

  /*  if (android.os.Build.VERSION.SDK_INT > 9) {
        StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
        StrictMode.setThreadPolicy(policy);
    }*/

    try {
        // Add your data
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
        nameValuePairs.add(new BasicNameValuePair("user_name", user));
        nameValuePairs.add(new BasicNameValuePair("user_pass", pass));
        nameValuePairs.add(new BasicNameValuePair("user_otp", null));
        nameValuePairs.add(new BasicNameValuePair("from_page", fpage));

        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

        // Execute HTTP Post Request
        HttpResponse response = httpclient.execute(httppost);

        String Rcode=response.toString();

        Toast.makeText(getBaseContext(), Rcode+"", Toast.LENGTH_LONG).show();

    } catch (ClientProtocolException e) {
        Toast.makeText(getBaseContext(), e+"", Toast.LENGTH_LONG).show();
    } catch (IOException e) {
        Toast.makeText(getBaseContext(), e+"", Toast.LENGTH_LONG).show();
    }
}

1 个答案:

答案 0 :(得分:0)

你可以在这里阅读:

HTTP response

10.2.1 200 OK

The request has succeeded.