【发布时间】: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 解决方法做很多事情。