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方法。你爲什麼做這個? –