我正在尝试发送用户并传递给asp webservice,但是当回复响应时会这样:
所以如何修复它并使其成为假的
这是我用过的网络服务链接:
http://ictfox.com/demo/Hafil_Updates/Login_Check.aspx?UserLogin=Demo&Password=Demo
02-20 19:57:23.326: D/Http Response:(4007): True<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title></title></head><body> <form name="form1" method="post" action="Login_Check.aspx?UserLogin=Demo&Password=Demo" id="form1"><input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwULLTE2MTY2ODcyMjlkZD/N053U40olll80mNvY/Qt2aBEc" /> <div> </div> </form></body></html>
这是我在asyncTask android中的全班:
HttpClient httpClient = new DefaultHttpClient();
// Creating HTTP Post
HttpPost httpPost = new HttpPost(
"http://ictfox.com/demo/Hafil_Updates/Login_Check.aspx?UserLogin=Demo&Password=Demo");
// Building post parameters
// key and value pair
List<NameValuePair> nameValuePair = new ArrayList<NameValuePair>(2);
nameValuePair.add(new BasicNameValuePair("UserLogin", "Demo"));
nameValuePair.add(new BasicNameValuePair("Password",
"Demo"));
// Url Encoding the POST parameters
try {
httpPost.setEntity(new UrlEncodedFormEntity(nameValuePair));
} catch (UnsupportedEncodingException e) {
// writing error to Log
e.printStackTrace();
}
// Making HTTP Request
try {
HttpResponse response = httpClient.execute(httpPost);
response.getEntity().getContentLength();
StringBuilder sb = new StringBuilder();
try {
BufferedReader reader =
new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line);
}
}
catch (IOException e) { e.printStackTrace(); }
catch (Exception e) { e.printStackTrace(); }
Log.d("Http Response:", sb.toString());
答案 0 :(得分:0)
是您或3dr派对的网络服务吗?它似乎不仅返回实际的返回值,还返回一些隐藏的HTML内容。检查是否有选项以只返回所需值或甚至更好的JSON的方式调用服务。如果没有,只需检查返回String是否以“True”
开头boolean success = sb.toString().toLowerCase().startsWith("true");
答案 1 :(得分:0)
您需要修改服务器发送的响应,这是最简单的事情。我看到你的服务器返回True
后跟一些HTML代码。让您的服务器删除HTML
如果您不想修改服务器端代码,只需查看子串True
的响应即可。
此外,为了获得响应,我使用了这个,这可能更简单:
httpresponse = httpclient.execute(httppost);
response = EntityUtils.toString(httpresponse.getEntity());