HttpPost在android系统不工作 [英] HttpPost in android not working
问题描述
我试图连接到使用HTTP POST,当我看到服务器的LOG文件Apache Tomcat服务器它显示获取/login/validate_doc.jsp HTTP / 1.1200 685
I am trying to connect to apache tomcat server using HTTP POST, when i see LOG file of server it showing GET /login/validate_doc.jsp HTTP/1.1" 200 685 ,
这意味着它越来越当我发送使用HttpPost和表单参数没有被服务器接收到一个GET请求。
which means it is getting a GET request when i am sending using HttpPost and form parameters are not received by server.
我的code是如下:
HttpPost post_http=null;
post_http=new HttpPost("http://somexx.ac.in/medONmob/validate_doc.jsp");
try
{
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("username",username));
nameValuePairs.add(new BasicNameValuePair("password",password));
post_http.setEntity(new UrlEncodedFormEntity(nameValuePairs));
我在哪里错了...?帮我请
Where am i wrong ...??? Help me out please
推荐答案
构建UrlEn codedFormEntity尝试时指定编码。默认情况下为ISO-8859-1。
同时这会让你的code未来的安全
Try specifying encoding when constructing UrlEncodedFormEntity. By default it is ISO-8859-1. Also this will make your code future safe
<一个href=\"http://stackoverflow.com/questions/10942205/creating-a-urlen$c$cdformentity-from-a-list-of-namevaluepairs-throws-a-nullpoint\">Creating根据NameValuePair列表的UrlEn codedFormEntity抛出一个NullPointerException异常
这篇关于HttpPost在android系统不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!