HTTPResponse 的内容长度有限制吗?

发布于 2024-09-15 23:08:20 字数 1523 浏览 1 评论 0原文

运行我的单元测试,我发现在 Android 上我没有收到完整的原子文档,而代码对于 JSE 工作正常。

网址为:https://www. googleapis.com/buzz/v1/activities/@me/@conspiration?max-results=25

请求标头为: 授权:[oauth oauth_token =“有效token”,oauth_consumer_key =“匿名”,oauth_version =“ 1.0”,oauth_signature_method =“ hmac-sha1”,oauth_timestamp =“签名=“有效签名”]

代码发出 HTTP 请求

public static String send( HttpsURLConnection request )
    throws BuzzIOException
{
    StringBuffer response = null;
    try
    {
        // Send request
        request.connect();

        // Read response
        InputStream is = request.getInputStream();
        response = new StringBuffer();
        byte[] b = new byte[4096];
        for ( int n; ( n = is.read( b ) ) != -1; )
        {
            response.append( new String( b, 0, n ) );
        }
    }
    catch ( Exception e )
    {
        throw new BuzzIOException( e );
    }
    //TODO remove debug line, i could set log4j but it is not compatible with android

    try{

        Class<?> clazz = Class.forName("android.util.Log");
        Method androidLog = clazz.getMethod("d", new Class[]{String.class,String.class});
        androidLog.invoke(null, "BuzzIO",response.toString());
    } catch (Exception e) {
        System.out.println(response.toString());
    }

    return response.toString();
}

我收到的响应是无效的原子提要,因为它被截断了。预期长度约为 86043 个字符,但我收到的响应只有 4435 个字符

Running my unit tests I have found that on android I am not receiving the complete atom document while the code works ok for JSE.

The URL is: https://www.googleapis.com/buzz/v1/activities/@me/@consumption?max-results=25

The request headers are:
authorization: [OAuth oauth_token="validToken", oauth_consumer_key="anonymous", oauth_version="1.0", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1282297108", oauth_nonce="5247048527864989575", oauth_signature="validSignature"]

The code to make the HTTP request

public static String send( HttpsURLConnection request )
    throws BuzzIOException
{
    StringBuffer response = null;
    try
    {
        // Send request
        request.connect();

        // Read response
        InputStream is = request.getInputStream();
        response = new StringBuffer();
        byte[] b = new byte[4096];
        for ( int n; ( n = is.read( b ) ) != -1; )
        {
            response.append( new String( b, 0, n ) );
        }
    }
    catch ( Exception e )
    {
        throw new BuzzIOException( e );
    }
    //TODO remove debug line, i could set log4j but it is not compatible with android

    try{

        Class<?> clazz = Class.forName("android.util.Log");
        Method androidLog = clazz.getMethod("d", new Class[]{String.class,String.class});
        androidLog.invoke(null, "BuzzIO",response.toString());
    } catch (Exception e) {
        System.out.println(response.toString());
    }

    return response.toString();
}

The response I receive is an invalid atom feed because it gets truncated. the expected length is about 86043 characters but I am getting a response with only 4435

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文