调用ASP web服务无法正常工作,因为我需要 [英] calling asp webservice not working as i need

查看:97
本文介绍了调用ASP web服务无法正常工作,因为我需要的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图发送用户,并传递给ASP web服务,但得到回来时,得到的反应是这样的:

所以如何解决它,并得到假真

这是Web服务的链接我已经使用:

  http://ictfox.com/demo/Hafil_Updates/Login_Check.aspx?UserLogin=Demo&Password=Demo
02-20 19:57:23.326:D / HTTP响应:(4007):真&LT; D​​OCTYPE HTML PUBLIC - // W3C // DTD XHTML 1.0过渡// ENhttp://www.w3.org/! TR / XHTML1 / DTD / XHTML1-transitional.dtd&GT;&LT; HTML xmlns=\"http://www.w3.org/1999/xhtml\"><head><title></title></head><body> &LT;表格名称=Form1的方法=邮报行动=Login_Check.aspx用户登陆=演示和放大器;放大器;密码=演示ID =form1的&GT;&LT;输入类型=隐藏的名字=__ VIEWSTATE ID =__ VIEWSTATEVALUE =/ wEPDwULLTE2MTY2ODcyMjlkZD / N053U40olll80mNvY / Qt2aBEc/&GT; &LT; D​​IV&GT; &LT; / DIV&GT; &LT; /形式为GT;&LT; /身体GT;&LT; / HTML&GT;

这是我在AsyncTask的机器人满级:

 的HttpClient HttpClient的=新DefaultHttpClient();
    //创建HTTP POST
    HttpPost httpPost =新HttpPost(
            http://ictfox.com/demo/Hafil_Updates/Login_Check.aspx?UserLogin=Demo&Password=Demo);    //大厦后的参数
    //键值对
    清单&LT;&的NameValuePair GT;的NameValuePair =新的ArrayList&LT;&的NameValuePair GT;(2);
    nameValuePair.add(新BasicNameValuePair(用户登陆,演示));
    nameValuePair.add(新BasicNameValuePair(密码
            DEMO));    // URL编码的POST参数
    尝试{
        httpPost.setEntity(新UrlEn codedFormEntity(的NameValuePair));
    }赶上(UnsupportedEncodingException五){
        //写入错误日志
        e.printStackTrace();
    }    //使HTTP请求
    尝试{
        HTT presponse响应= httpClient.execute(httpPost);        。response.getEntity()getContentLength();
        StringBuilder的SB =新的StringBuilder();
        尝试{
            BufferedReader中读者=
                   新的BufferedReader(新的InputStreamReader(response.getEntity()的getContent()));
            串线= NULL;            而((行= reader.readLine())!= NULL){
                sb.append(线);
            }
        }
        赶上(IOException异常五){e.printStackTrace(); }
        赶上(例外五){e.printStackTrace(); }
        Log.d(HTTP响应:sb.toString());


解决方案

您需要修改服务器发送的响应,这将是最容易的事。我看到你服务器返回其次是一些HTML code 。让你的服务器中删除HTML

如果您不想修改服务器端code,只是看在你的子响应

此外,要获得我用这个响应,其可以是简单的:

  HTT presponse = httpclient.execute(httppost);
响应= EntityUtils.toString(HTT presponse.getEntity());

I'm trying to send user and pass to asp webservice , but when getting back response get like this :

so how to fix it and get true of false

this is webservice link i have used :

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>

this is my full class in 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());

解决方案

You would need to modify the response sent by the server, that would be the easiest thing to do. I see that you server returns True followed by some HTML code. Make your server remove the HTML

If you don't want to modify the server side code, just look in your response for the substring True.

Additionally, to get the response I use this, which may be simpler:

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

这篇关于调用ASP web服务无法正常工作,因为我需要的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆