Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/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
在android 5.0.2(assus ZenPad 8.0 z380KL)上使用HttpURLConnection时没有响应_Android_Httpurlconnection - Fatal编程技术网

在android 5.0.2(assus ZenPad 8.0 z380KL)上使用HttpURLConnection时没有响应

在android 5.0.2(assus ZenPad 8.0 z380KL)上使用HttpURLConnection时没有响应,android,httpurlconnection,Android,Httpurlconnection,在安卓5.0.2 assus zenpad 8平板电脑上,仅通过移动数据获取asp.net Web服务的响应时,我面临着一些问题 一切正常,直到ws开始延迟响应超过50秒/60秒 其他的平板电脑和手机都能正常工作,到目前为止,我不知道是什么导致了这种行为 public String test(int delayResponse) { URL url; HttpURLConnection connection = null; try { url = new

在安卓5.0.2 assus zenpad 8平板电脑上,仅通过移动数据获取asp.net Web服务的响应时,我面临着一些问题

一切正常,直到ws开始延迟响应超过50秒/60秒

其他的平板电脑和手机都能正常工作,到目前为止,我不知道是什么导致了这种行为

public String test(int delayResponse) {
    URL url;
    HttpURLConnection connection = null;
    try {
        url = new URL("http://192.168.1.10/Test.asmx");

        String requestMessage = getRequest(delayResponse);

        connection = (HttpURLConnection) url.openConnection();


        Log.i("ReadTimeout", Integer.toString(connection.getReadTimeout()));
        connection.setChunkedStreamingMode(0);
        connection.setRequestMethod("POST");
        connection.setRequestProperty("Content-Type", "text/xml; charset=utf-8;");
        connection.setRequestProperty("SOAPAction", "http://tempuri.org/TestConectivity");

        connection.setRequestProperty("Content-Length", Integer.toString(requestMessage.getBytes().length));

        connection.setConnectTimeout(1000);
        connection.setReadTimeout((delayResponse + 10)*1000);

        connection.setUseCaches(false);
        connection.setDoInput(true);
        connection.setDoOutput(true);
        connection.connect();

        DataOutputStream wr = new DataOutputStream(connection.getOutputStream());
        wr.writeBytes(requestMessage);
        wr.flush();
        wr.close();

        if ( connection.getResponseCode() == 200) {

                StringBuilder sbResponse = new StringBuilder();

                InputStream stream = connection.getInputStream();

                InputStreamReader isReader = new InputStreamReader(stream ); 
                BufferedReader br = new BufferedReader(isReader);
                String line;
                while ((line = br.readLine()) != null) {
                    sbResponse.append(line);
                }
                br.close();
                isReader.close();
                stream.close();
                return sbResponse.toString();
        }
        else {
            return Integer.toString(connection.getResponseCode());
        }
    } catch (MalformedURLException e) {
        e.printStackTrace();
        return e.getMessage();
    } catch (IOException e) {
        e.printStackTrace();
        return e.getMessage() + e.toString();
    } finally {
        if (connection != null) {
            connection.disconnect();
        }
    }
}

private String getRequest(int delayResponse) {
    StringBuilder sb = new StringBuilder();
    sb.append("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
    sb.append("<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">");
    sb.append("<soap:Body>");
    sb.append("<TestConectivity xmlns=\"http://tempuri.org/\">");
    sb.append("<delayResponse>"+Integer.toString(delayResponse)+"</delayResponse>");
    sb.append("</TestConectivity>");
    sb.append("</soap:Body>");
    sb.append("</soap:Envelope>");
    return sb.toString();
}
公共字符串测试(int-delayResponse){
网址;
HttpURLConnection=null;
试一试{
url=新url(“http://192.168.1.10/Test.asmx");
String requestMessage=getRequest(delayResponse);
connection=(HttpURLConnection)url.openConnection();
Log.i(“ReadTimeout”,Integer.toString(connection.getReadTimeout());
connection.setChunkedStreamingMode(0);
connection.setRequestMethod(“POST”);
setRequestProperty(“内容类型”,“text/xml;charset=utf-8;”);
connection.setRequestProperty(“SOAPAction”http://tempuri.org/TestConectivity");
setRequestProperty(“内容长度”,Integer.toString(requestMessage.getBytes().Length));
连接。设置连接超时(1000);
connection.setReadTimeout((delayResponse+10)*1000);
connection.setUseCaches(false);
connection.setDoInput(true);
connection.setDoOutput(真);
connection.connect();
DataOutputStream wr=新的DataOutputStream(connection.getOutputStream());
wr.writeBytes(请求消息);
wr.flush();
wr.close();
if(connection.getResponseCode()==200){
StringBuilder sbResponse=新建StringBuilder();
InputStream=connection.getInputStream();
InputStreamReader isReader=新的InputStreamReader(流);
BufferedReader br=新的BufferedReader(isReader);
弦线;
而((line=br.readLine())!=null){
sbResponse.append(行);
}
br.close();
isReader.close();
stream.close();
返回sbResponse.toString();
}
否则{
返回Integer.toString(connection.getResponseCode());
}
}捕获(格式错误){
e、 printStackTrace();
返回e.getMessage();
}捕获(IOE异常){
e、 printStackTrace();
返回e.getMessage()+e.toString();
}最后{
if(连接!=null){
连接断开();
}
}
}
私有字符串getRequest(int delayResponse){
StringBuilder sb=新的StringBuilder();
某人加上(“”);
某人加上(“”);
某人加上(“”);
某人加上(“”);
sb.append(“+Integer.toString(delayResponse)+”);
某人加上(“”);
某人加上(“”);
某人加上(“”);
使某人返回字符串();
}
这是ws代码的片段

/// <summary>
/// Summary description for Test
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
public class Test : System.Web.Services.WebService
{

    [WebMethod]
    public string TestConectivity(int delayResponse)
    {
        System.Threading.Thread.Sleep(delayResponse * 1000);
        return "Hello World";
    }
}
//
///测试概要说明
/// 
[WebService(命名空间=”http://tempuri.org/")]
[WebServiceBinding(ConformsTo=WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
公共类测试:System.Web.Services.WebService
{
[网络方法]
公共字符串testconctivity(int delayResponse)
{
系统.线程.线程.睡眠(延迟响应*1000);
返回“你好世界”;
}
}

一些gsm运营商(在我的例子中是沃达丰)通过公共APN连接超时。。。想想他们的网络专家觉得有必要优化他们的4G,我很高兴他们的竞争对手没有尝试使用okhttp()