我想使用Httpost
发布一些消息。
我知道我需要发布的值对。我使用已经执行的其他HttpClient
中的CookieStore
和AsyncTask
。但为什么messege帖子页面会自行返回??
public void postData(String login, String label, String messege) throws URISyntaxException {
HttpResponse response;
HttpContext localContext = new BasicHttpContext();
localContext.setAttribute(ClientContext.COOKIE_STORE, Authorization.cookieStore);
try {
HttpPost httppost = new HttpPost("http://www.x-bikers.ru/ls/add_msg_e.php");
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("action2", "post"));
nameValuePairs.add(new BasicNameValuePair("name2", login));
nameValuePairs.add(new BasicNameValuePair("fmt_name", label));
nameValuePairs.add(new BasicNameValuePair("msg", messege));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs, "CP1251"));
response = Authorization.httpClient.execute(httppost, localContext);
// Execute HTTP Post Request
HttpEntity entity = response.getEntity();
InputStreamReader content = new InputStreamReader(entity.getContent(), "windows-1251");
BufferedReader reader = new BufferedReader(content);
String line;
while ((line = reader.readLine()) != null) {
builder.append(line);
}
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
} catch (IOException e) {
// TODO Auto-generated catch block
}
}