【问题标题】:response code always give 200响应代码总是给出 200
【发布时间】:2014-03-31 21:02:19
【问题描述】:

我正在尝试使用 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();
    }
}

【问题讨论】:

  • 你为什么不尝试打印响应而不是 statusCode()
  • 首先,不要像那样留下空的 catch 块。其次,根据页面的来源,您的网址似乎是login.php,而不是index.php。最后,永远不要使用permitAll
  • 好吧,伙计们,我用了你的提示......请检查编辑的问题文本agine ...顺便说一句,我是android新手!

标签: java android http-post server-response


【解决方案1】:

你可以在这里阅读:

HTTP response

10.2.1 200 OK

The request has succeeded. 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-06-14
    • 2018-05-16
    • 2014-09-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-09
    • 2013-09-08
    相关资源
    最近更新 更多