当我正在使用的库(路标1.1-SNAPSHOT)时,我似乎在Android 1.5上遇到了一个特殊的问题,它连续两次连接到远程服务器.第二个连接始终失败了HttpURLConnection.getResponseCode()的-1
这是一个暴露问题的测试用例:
// BROKEN
public void testDefaultOAuthConsumerAndroidBug() throws Exception {
for (int i = 0; i < 2; ++i) {
final HttpURLConnection c = (HttpURLConnection) new URL("https://api.tripit.com/oauth/request_token").openConnection();
final DefaultOAuthConsumer consumer = new DefaultOAuthConsumer(api_key, api_secret, SignatureMethod.HMAC_SHA1);
consumer.sign(c); // This line...
final InputStream is = c.getInputStream();
while( is.read() >= 0 ) ; // ... in combination with this line causes responseCode -1 for i==1 when using api.tripit.com but not mail.google.com
assertTrue(c.getResponseCode() > 0);
}
}
Run Code Online (Sandbox Code Playgroud)
基本上,如果我签署请求然后使用整个输入流,则下一个请求将失败,结果代码为-1.如果我只是从输入流中读取一个字符,似乎不会发生故障.
请注意,任何网址都不会发生这种情况 - …