【发布时间】:2012-11-21 23:21:30
【问题描述】:
我正在尝试帮助学生编写一个将联系特定网络服务器的 Android 应用程序。从网站的外观来看,您可以使用 Web 浏览器发出 GET 请求,然后返回 cookie 会话和“真实性令牌”(将页面来源视为不可见输入)
我们发出一个 GET 请求,然后想要跟进该帖子,但我们在帖子中收到状态代码 404。附带说明一下,第一个 GET 请求返回的代码是 200。
有人有什么想法吗?下面是被执行的代码...
public void run()
{
HttpClient httpClient = new DefaultHttpClient();
HttpGet httpGet = new HttpGet("https://co22.herokuapp.com/login/");
HttpPost httpPost = new HttpPost("https://co22.herokuapp.com/login/sessions");
HttpResponse response;
try
{
response = httpClient.execute(httpGet);
Log.d("matt",response.getStatusLine().toString());
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("session[network_id]", username));
nameValuePairs.add(new BasicNameValuePair("session[password]", password));
nameValuePairs.add(new BasicNameValuePair("authenticity_token","9yvxPOUpRFdsTeHAZtISEfBHpElDTHzvMjAbQnxOHDM="));
httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
response = httpClient.execute(httpPost);
Log.d("matt",response.getStatusLine().toString());
}
catch (ClientProtocolException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
【问题讨论】:
-
“帮助学生写作”——“学习”不是指自己做某事吗?
-
如果教授不能帮他学习,教授有什么用?
-
那么,也许他不应该是学生。
-
你说你在 GET 请求中取回了一个带有真实性令牌的 cookie,但这里看起来真实性令牌是硬编码的。它是哪个?
-
@JohnLeehey 实际上两者都...返回了一个 cookie 和一个硬编码的令牌。您可以在源 HTML 文件中查看令牌
标签: android cookies http-post httpclient http-get