从android服务器访问来自其他国家的php服务器获取空白响应

时间:2014-04-11 16:02:17

标签: java android connection httpresponse

我做了一个andoid应用程序,我从php服务器得到响应,请求POST格式。我正在使用以下代码进行http连接:

// random string as boundary for multi-part http post
    String strBoundary = "3i2ndDfv2rTHiSisAbouNdArYfORhtTPEefj3q2f";
    String endLine = "\r\n";

    OutputStream os;

    String url = encodeUrl(methodType, graphURL, params);
    Log.d("url - ",url);


    Log.d("Method Type - ", methodType + " URL - " + url);

    HttpURLConnection conn = (HttpURLConnection) new URL(url)
            .openConnection();
    conn.setConnectTimeout(60000);
    conn.setReadTimeout(30000);

    conn.setRequestProperty("User-Agent", System.getProperties()
            .getProperty("http.agent"));


    if (!methodType.equals("GET")) {
        Bundle dataparams = new Bundle();
        for (String key : params.keySet()) {
            if (params.getByteArray(key) != null) {
                dataparams.putByteArray(key, params.getByteArray(key));
            }
        }

        // use method override
        if (!params.containsKey("method")) {
            params.putString("method", methodType);
        }

        if (params.containsKey("access_token")) {
            @SuppressWarnings("deprecation")
            String decoded_token = URLDecoder.decode(params
                    .getString("access_token"));
            params.putString("access_token", decoded_token);
        }

        conn.setRequestMethod("POST");
        conn.setRequestProperty("Content-Type",
                "multipart/form-data;boundary=" + strBoundary);
        conn.setDoOutput(true);
        conn.setDoInput(true);
        conn.setRequestProperty("Connection", "Keep-Alive");
        conn.connect();

        os = new BufferedOutputStream(conn.getOutputStream());

        os.write(("--" + strBoundary + endLine).getBytes());
        os.write((encodePostBody(params, strBoundary)).getBytes());
        os.write((endLine + "--" + strBoundary + endLine).getBytes());

        if (!dataparams.isEmpty()) {
            for (String key : dataparams.keySet()) {                    
                os.write(("Content-Disposition: form-data; filename=\""
                        + key + "\"" + endLine).getBytes());
                os
                        .write(("Content-Type: content/unknown" + endLine + endLine)
                                .getBytes());
                os.write(dataparams.getByteArray(key));
                os.write((endLine + "--" + strBoundary + endLine)
                        .getBytes());
            }
        }
        os.flush();
    }

    String response = "";
    try {
        response = parseXmlSvn(conn.getInputStream());
    } catch (FileNotFoundException e) {
        // Error Stream contains JSON that we can parse to a FB error
        //response = read(conn.getErrorStream());
        Log.i("RESPONSE",""+response);
    }
    Log.i("RESPONSE", ""+response);
    return response;

我的演示服务器上的一切正常,我将PHP服务上传到客户端服务器。我也从他的服务器得到了适当的回应。 但是当客户端在他的Android设备中访问其他国家的3G或4G中的应用程序时,他正在获得空白响应,而同一服务器的相同服务可以通过他轻松访问iOS代码。在收到回复或任何其他问题时是丢包吗?

我真的很感激你能给我的任何帮助。 感谢

0 个答案:

没有答案