内容最大长度? [英] Maximum length of content?

查看:189
本文介绍了内容最大长度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用的HttpURLConnection 服务器连接,但我有PUT方法有问题。
我需要发送一个字符串的 1500字的(或以上),但在这种情况下,服务器产生超时并返回 500 - 服务器内部错误
。 如果我把不是String较低的 1400字的,我没有问题,服务器返回确定

I'm trying to connect with a server using HttpURLConnection, but I have a problem with the PUT method.
I need to send a String with 1500 characters (or more), but in this case the server produces a timeout and returns 500 - server internal error.
If I send a String lower than 1400 characters, I have not problem and the server returns OK.

我的code是如下:

public String connectToServer(String prototype) {
    String responseString = "";

    try {
        BufferedReader in = new BufferedReader(new InputStreamReader(openURLForInput(new URL(URL), USERNAME, PASSWORD, prototype)));
        String line;
        while ((line = in.readLine()) != null) {
            System.out.println(line);
            responseString += line;
        }

    } catch (IOException e) {
        e.printStackTrace();
        responseString = e.toString();
    }

    return responseString;
}

// -----------------------

//-----------------------

public InputStream openURLForInput(URL url, String uname, String pword, String content) throws IOException {
    HttpURLConnection conn = (HttpURLConnection) url.openConnection();
    conn.setDoInput(true);
    conn.setDoOutput(true);
    conn.setRequestProperty("Authorization", userNamePasswordBase64(uname, pword)); // I know this is OK
    conn.addRequestProperty("Content-type", "application/xml; charset=utf-8");

    //conn.setChunkedStreamingMode(8 * 1024);

    conn.setRequestMethod("PUT");
    conn.connect();

    OutputStream output = conn.getOutputStream();
    OutputStreamWriter osw = new OutputStreamWriter(output, "UTF-8");
    BufferedWriter writer = new BufferedWriter(osw);
    writer.write(content); // content length  > 1400 characters
    writer.close();
    output.close();

    int status = conn.getResponseCode();
    Log.i("STATUS", status + "");
    Log.i("STATUS_ERROR", conn.getResponseMessage());

    return conn.getInputStream();
}

我trye​​d添加行

I tryed adding the lines

conn.setFixedLengthStreamingMode(contentLength)
conn.setChunkedStreamingMode(8 * 1024);

但服务器的答案是错的呢。

But the server's answer is wrong anyway.

更新:

我能发现问题。出于某种原因,当我尝试在请求中发送大量人体的,该服务器产生超时但不是所有的网络,只能用一些网络。我使用安全连接如SSL,也许这能带来的问题?

I could detect the problem. For some reason, when I try to send large bodys in the request, the server produces a timeout but not with all networks, only with some networks. I use a secure conection SSL, maybe this can bring problems?

推荐答案

也许这是一个网络的MTU的问题,我说你研究在这一方面。

Maybe it's a network MTU problem, I'd say you investigate on that front.

下面是有关Windows中的一个表:

Here's a table relevant to windows:

Network             MTU (bytes)
-------------------------------
16 Mbps Token Ring        17914
4 Mbps Token Ring          4464
FDDI                       4352
Ethernet                   1500
IEEE 802.3/802.2           1492
PPPoE (WAN Miniport)       1480
X.25                        576

这篇关于内容最大长度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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