0

我正在尝试从 android 调用我的 wcf webservices 但是在读取响应流时我得到的只是这个

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">
\n<HTML>
<HEAD><TITLE>Bad Request</TITLE>
\n<META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii"></HEAD>
\n<BODY><h2>Bad Request - Invalid Hostname</h2>
\n<hr><p>HTTP Error 400. The request hostname is invalid.</p>
\n</BODY></HTML>\n

这是我的客户端

String result = "";
    String url ="http://10.0.2.2:81/WScom.svc/GetUserList";
    InputStream is = null;
    try {

        HttpClient httpclient = new DefaultHttpClient();

        HttpPost httppost = new HttpPost(url);


        httppost.setHeader("Accept", "application/json");
        httppost.setHeader("Content-Type", "application/json");


        HttpResponse response = httpclient.execute(httppost);

        HttpEntity entity = response.getEntity();

        is = entity.getContent();

    } catch (Exception e) {
        result = e.toString();
    }

    try {
    BufferedReader reader = null;
    StringBuilder sb = new StringBuilder();

    reader = new BufferedReader(new InputStreamReader(is));
    String line = "";
    while ((line = reader.readLine()) != null) {
        sb.append(line + "\n");
        //System.out.println(line);
    }

    result = sb.toString();

        is.close();
    } 
    catch (Exception e) {

        result = e.toString();
    }
    return (result);
}       

尽管当我将链接粘贴到浏览器中时(当然,由于 android 模拟器的要求,使用 localhost 而不是 10.0.2.2)它显示了完美的 json 结果!所以有什么帮助吗?

4

0 回答 0