如何将 HttpGet 转换为 HttpPost?
我正在使用 HttpGet 方法从我的 Android 应用程序的 Web 服务检索数据。谁能告诉我如何将下面给出的代码转换为 HttpPost 方法?
String url = URLEditor.encode("http://"+Constants.strURL+"Orders.asmx/CheckWebConnection?TechCode="+username+"&TechPIN="+password);
HttpClient httpClient = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(url);
response = httpClient.execute(httpGet);
HttpEntity entity = response.getEntity();
if(entity == null) return false;
is = entity.getContent();
预先感谢...
感谢您帮助我..
我尝试使用上面给出的代码。但我得到的 Document 对象为 NULL。这是我得到的 doc 为 NULL 的代码
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost("http://"+Constants.strURL+"Orders.asmx/CheckWebConnection");
List<NameValuePair> nvpList = new ArrayList<NameValuePair>();
nvpList.add(new BasicNameValuePair("TechCode", techcode));
nvpList.add(new BasicNameValuePair("TechPIN", techpin));
httpPost.setEntity(new UrlEncodedFormEntity(nvpList));
HttpResponse response = httpClient.execute(httpPost);
HttpEntity entity = response.getEntity();
InputStream is = entity.getContent();
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(is);
。我使用 HttpGet 时没有问题。怎么解决呢?请帮忙
I'm using HttpGet method for retrieving data from a web service from my Android app. Can anyone tell me how to convert the below given code to HttpPost method?
String url = URLEditor.encode("http://"+Constants.strURL+"Orders.asmx/CheckWebConnection?TechCode="+username+"&TechPIN="+password);
HttpClient httpClient = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(url);
response = httpClient.execute(httpGet);
HttpEntity entity = response.getEntity();
if(entity == null) return false;
is = entity.getContent();
Thanks in advance...
thanks for helping me..
I tried with the code given above. But I get Document object as NULL. This's the code
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost("http://"+Constants.strURL+"Orders.asmx/CheckWebConnection");
List<NameValuePair> nvpList = new ArrayList<NameValuePair>();
nvpList.add(new BasicNameValuePair("TechCode", techcode));
nvpList.add(new BasicNameValuePair("TechPIN", techpin));
httpPost.setEntity(new UrlEncodedFormEntity(nvpList));
HttpResponse response = httpClient.execute(httpPost);
HttpEntity entity = response.getEntity();
InputStream is = entity.getContent();
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(is);
I get doc as NULL. No issues when I use HttpGet. How can it be solved? Please help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是代码,这会对您有所帮助。
Here is the code, this will help you.