Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/196.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/google-app-engine/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 调用asp Web服务未按我需要的方式工作_Java_Android_Asp.net_Web Services - Fatal编程技术网

Java 调用asp Web服务未按我需要的方式工作

Java 调用asp Web服务未按我需要的方式工作,java,android,asp.net,web-services,Java,Android,Asp.net,Web Services,我正在尝试发送用户并传递给asp webservice,但当返回响应时,得到如下结果: 那么,如何修复它并实现错误呢 这是我使用过的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

我正在尝试发送用户并传递给asp webservice,但当返回响应时,得到如下结果:

那么,如何修复它并实现错误呢

这是我使用过的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&amp;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());

那是你的网络服务还是3dr派对?似乎它不仅返回实际的返回值,还返回一些隐藏的HTML内容。检查是否有选项以只返回所需值或更好的JSON的方式调用服务。如果不是,只需检查返回字符串是否以True开头

boolean success = sb.toString().toLowerCase().startsWith("true");

您需要修改服务器发送的响应,这将是最简单的操作。我看到服务器返回True,后面是一些HTML代码。使您的服务器删除HTML

如果不想修改服务器端代码,只需在响应中查找子字符串True

此外,为了得到响应,我使用了以下更简单的方法:

httpresponse = httpclient.execute(httppost);
response = EntityUtils.toString(httpresponse.getEntity());

为什么它允许返回true?我输入了无效数据,但返回了true。它总是返回true,问题出在服务器上,而不是应用程序上。