-1
我建設,我想提出一個登錄頁面簡單的Android應用程序,並實現一個簡單的Web發佈的API返回HTML而不是JSON。以前它工作正常,但突然就停止工作,現在它總是返回我的HTML代碼。以下是我的代碼,POST請求總是在android系統
try {
List<NameValuePair> li = new ArrayList<NameValuePair>();
li.add(new BasicNameValuePair("username", "[email protected]"));
li.add(new BasicNameValuePair("password", "123456dndjsj789"));
li.add(new BasicNameValuePair("key", "ZATXMhjHartjDTrH"));
HttpClient httpClient = new DefaultHttpClient();
HttpEntity httpEntity = null;
HttpResponse httpResponse = null;
HttpPost httppost = new HttpPost("http://www.deal.com.lb/merchant_ws/login_ws.php");
httppost.setHeader("Content-Type", "text/html");
httppost.setHeader("Accept","application/json");
httppost.setEntity(new UrlEncodedFormEntity(li));
httpResponse = httpClient.execute(httppost);
httpEntity = httpResponse.getEntity();
String response = EntityUtils.toString(httpEntity);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
請告訴我我寫錯了哪段代碼。此服務也作爲GET請求工作。你可以在瀏覽器中試用它。在瀏覽器中它正常工作,但在Android代碼中不是。
順便說一句,如果這些都是真實的API證書,則需要從服務的所有者請求新集 - 一旦你讓他們發佈在網絡上,你可以假設別人會開始使用它們。 – halfer
你的建議 –
好感謝名單你有我的問題的答案 –