第三方应用程序中的HttpPost [Android]

时间:2014-02-05 14:57:03

标签: android http http-post

我尝试将应用制作某个网站的移动版本,这需要授权。 这是网站的登录表单

<form method="post" 
    action="loginAuth.php" 
    autocomplete="off">
    <input id="username" 
        name="username" 
        type="text" 
        class="inp" />
    <input id="password" 
        name="password" 
        type="password" 
        class="inp" />
    <input type="submit" 
        class="q-button" 
        name="LogIn" 
        value=" Log In"/>
</form>

这是我的代码:

public String postData() {
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost(url + "loginAuth.php");
    try {
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
        nameValuePairs.add(new BasicNameValuePair("username", username));
        nameValuePairs.add(new BasicNameValuePair("password", password));
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs, "UTF-8"));

        HttpResponse response = httpclient.execute(httppost);
        HttpEntity entity = response.getEntity();
        if (entity != null) {
            String responseBody = EntityUtils.toString(entity);
            return responseBody;
        } else {
            return null;
        }

    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}

问题是我无法授权,postData()方法会再次返回授权页面。

1 个答案:

答案 0 :(得分:0)

您应该确保本网站不使用SSL,如果没有证书则无法提出SSL请求

相关问题