0
我正在使用HttpGet方法从我的Android应用程序中从Web服务中检索数据。任何人都可以告诉我如何将下面给出的代码转换为HttpPost方法?如何将HttpGet转换为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。这是代码
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);
我将doc作为NULL。当我使用HttpGet时没有问题。它如何解决?请帮忙
如果Web服务没有对POST做出响应,那么您的运气会很不好。从GET到POST没有真正的“切换”;他们是不同的http方法。你为什么做这个? –