-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
你的建议 –
好感谢名单你有我的问题的答案 –