运行我的单元测试我发现在 android 上我没有收到完整的 atom 文档,而代码对于 JSE 工作正常。
网址是:https ://www.googleapis.com/buzz/v1/activities/@me/@consumption?max-results=25
请求头是:授权:[OAuth oauth_token="validToken", oauth_consumer_key="anonymous", oauth_version="1.0", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1282297108", oauth_nonce="5247048527864989575", oauth_sign有效签名"]
发出 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