我目前正在处理一个应用程序.. 在那个应用程序中,我必须使用 get 和 post 这两种方法.. get 方法正常工作,但在 post 方法中突然得到类似的响应
"invalid method.post required"..
我的代码是:
String list_url = "************************";
try {
String appand = TimeStampForAuth.TimeStameMethod(main.this);
String auth = android.util.Base64.encodeToString(("iphone" + ":" +
"2a5a262d5a")
.getBytes("UTF-8"), android.util.Base64.NO_WRAP);
DefaultHttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(list_url+appand);
Log.d("URL_LIST", list_url+appand);
List nvps = new ArrayList();
nvps.add(new BasicNameValuePair("login",Login));
nvps.add(new BasicNameValuePair("password",password));
nvps.add(new BasicNameValuePair("title",title));
nvps.add(new BasicNameValuePair("category_id",cat_id));
UrlEncodedFormEntity p_entity = new UrlEncodedFormEntity(nvps,HTTP.UTF_8);
post.addHeader("Authorization", "Basic " + auth);
post.setEntity(p_entity);
HttpResponse response = client.execute(post);
HttpEntity responseEntity = response.getEntity();
String s = EntityUtils.toString(responseEntity);
Log.d("List response", s);
}
catch(Exception e){
System.out.println(e.toString());
}
因为我遗漏了一些东西或者我不知道的东西..所有这些东西都对 post 方法有效....
请尽早帮助我...
谢谢你............
最佳答案
尝试使用 setHeader()
而不是 addHeader()
关于android - 如何使用http post方法设置标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7092252/