android中的Webservice显示服务器超时错误

时间:2016-02-29 07:24:46

标签: android web-services

第一次尝试在android中调用.Net webservice。 Webservice在高级Web客户端chrom扩展中完美运行。

enter image description here

但是在Android代码下面,它显示服务器超时异常。

final int DEFAULT_TIMEOUT = 200000 * 1000000000 * 1000000000;
            String str;


            progress.setMessage("Please Wait...");
            progress.setIndeterminate(false);
            progress.setCancelable(false);

            progress.show();
            // Make RESTful webservice call using AsyncHttpClient object
            AsyncHttpClient client = new AsyncHttpClient();
            client.setTimeout(DEFAULT_TIMEOUT);

            // failed
            client.post("http://10.0.2.2:8080/DService/ServiceSD.svc/LoginUser?Query=login=WT&password=03&includeUserMiscInfo=true",
                    new AsyncHttpResponseHandler() {


                        String str;

                public void onSuccess(int i, Header[] headers, byte[] bytes) {

                    try {
                        str = new String(bytes, "UTF-8");
                        Toast.makeText(getActivity().getApplicationContext(), "Returned"
                                + str, Toast.LENGTH_LONG).show();
                        progress.dismiss();

                    } catch (UnsupportedEncodingException e) {
                        e.printStackTrace();
                    }


                @Override
                public void onFailure(int i, Header[] headers, byte[] bytes, Throwable throwable) {
                    Toast.makeText(getActivity().getApplicationContext(), "Status code :" + i + "errmsg : " + throwable.getMessage(), Toast.LENGTH_LONG).show();
                    progress.dismiss();
                }

            }
            );

我是否正确调用了网络服务?欢迎任何建议。感谢。

1 个答案:

答案 0 :(得分:0)

我从我的ip中删除了端口号,它现在正在运行。