HTTPResponse 的内容长度有限制吗?
运行我的单元测试,我发现在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论