【问题标题】:HttpPost in third party application [Android]第三方应用程序中的 HttpPost [Android]
【发布时间】:2014-02-05 14:57:03
【问题描述】:

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

<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() 方法再次返回给我授权页面。

【问题讨论】:

  • 你有什么问题?
  • Budius,问题是我无法授权,postData() 方法再次返回给我授权页面。我想授权,但我不能
  • 重点是:应用程序访问云中内容的正确方式是通过公共 API 并使用自己的应用程序 KEY。您想要实现的是一种 hacky 解决方法,而您可以使用 hacky 解决方法做很多事情。

标签: android http http-post


【解决方案1】:

你应该确保这个网站不使用 SSL,如果没有他们的证书你不能提出 SSL 请求

【讨论】:

  • 谢谢。有没有其他方法可以在没有证书的情况下提出请求?
猜你喜欢
  • 1970-01-01
  • 2011-05-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-04-25
  • 1970-01-01
相关资源
最近更新 更多