我需要一个响应代码,但它会抛出一个 IOException。我不知道怎么回事!
try
{
url = new URL(urlBuilder.toString());
conn = (HttpURLConnection) url.openConnection();
conn.setDoInput(true);
conn.setConnectTimeout(TIME_OUT);
conn.setRequestMethod(METHOD_GET);
conn.setRequestProperty("accept", "*/*");
conn.connect();
int responseCode = conn.getResponseCode(); //throw IOException:Received authentication challenge is null
if (responseCode == HTTP_OK)
{
inStream = conn.getInputStream();
response = getResponse(inStream);
}
else
{
response = "response code:"+responseCode;
}
} catch (Exception e)
{
throw e;
}
finally
{
conn.disconnect();
}
return response;
}
IOException 是:
05-03 20:14:01.577: WARN/System.err(1515): java.io.IOException: Received authentication challenge is null
05-03 20:14:01.596: WARN/System.err(1515): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.doRequestInternal(HttpURLConnectionImpl.java:1694)
05-03 20:14:01.577: INFO/QQWeiBo(1515): Received authentication challenge is null
05-03 20:14:01.577: WARN/System.err(1515): java.io.IOException: Received authentication challenge is null
05-03 20:14:01.577: WARN/System.err(1515): java.io.IOException: Received authentication challenge is null
05-03 20:14:01.596: WARN/System.err(1515): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.doRequestInternal(HttpURLConnectionImpl.java:1694)
05-03 20:14:01.596: WARN/System.err(1515): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.doRequest(HttpURLConnectionImpl.java:1649)
05-03 20:14:01.596: WARN/System.err(1515): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:1374)
05-03 20:14:01.596: WARN/System.err(1515): at com.szy.weibo.service.SyncHttp.httpGet(SyncHttp.java:72)
05-03 20:14:01.596: WARN/System.err(1515): at com.szy.weibo.service.Weibo.getRequestToken(Weibo.java:45)
05-03 20:14:01.606: WARN/System.err(1515): at com.szy.weibo.MainActivity.startWebView(MainActivity.java:95)
05-03 20:14:01.606: WARN/System.err(1515): at com.szy.weibo.MainActivity.authorization(MainActivity.java:83)
05-03 20:14:01.606: WARN/System.err(1515): at com.szy.weibo.MainActivity$1.onClick(MainActivity.java:71)
05-03 20:14:01.606: WARN/System.err(1515): at android.view.View.performClick(View.java:2408)
05-03 20:14:01.596: WARN/System.err(1515): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.doRequestInternal(HttpURLConnectionImpl.java:1694)
05-03 20:14:01.596: WARN/System.err(1515): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.doRequest(HttpURLConnectionImpl.java:1649)
05-03 20:14:01.596: WARN/System.err(1515): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:1374)
05-03 20:14:01.596: WARN/System.err(1515): at com.szy.weibo.service.SyncHttp.httpGet(SyncHttp.java:72)
05-03 20:14:01.596: WARN/System.err(1515): at com.szy.weibo.service.Weibo.getRequestToken(Weibo.java:45)
05-03 20:14:01.606: WARN/System.err(1515): at com.szy.weibo.MainActivity.startWebView(MainActivity.java:95)
05-03 20:14:01.606: WARN/System.err(1515): at com.szy.weibo.MainActivity.authorization(MainActivity.java:83)
05-03 20:14:01.606: WARN/System.err(1515): at com.szy.weibo.MainActivity$1.onClick(MainActivity.java:71)
05-03 20:14:01.606: WARN/System.err(1515): at android.view.View.performClick(View.java:2408)
05-03 20:14:01.596: WARN/System.err(1515): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.doRequest(HttpURLConnectionImpl.java:1649)
05-03 20:14:01.596: WARN/System.err(1515): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:1374)
05-03 20:14:01.596: WARN/System.err(1515): at com.szy.weibo.service.SyncHttp.httpGet(SyncHttp.java:72)
05-03 20:14:01.596: WARN/System.err(1515): at com.szy.weibo.service.Weibo.getRequestToken(Weibo.java:45)
05-03 20:14:01.606: WARN/System.err(1515): at com.szy.weibo.MainActivity.startWebView(MainActivity.java:95)
05-03 20:14:01.606: WARN/System.err(1515): at com.szy.weibo.MainActivity.authorization(MainActivity.java:83)
05-03 20:14:01.606: WARN/System.err(1515): at com.szy.weibo.MainActivity$1.onClick(MainActivity.java:71)
05-03 20:14:01.606: WARN/System.err(1515): at android.view.View.performClick(View.java:2408)
05-03 20:14:01.606: WARN/System.err(1515): at android.view.View$PerformClick.run(View.java:8816)
05-03 20:14:01.616: WARN/System.err(1515): at android.os.Handler.handleCallback(Handler.java:587)
05-03 20:14:01.627: WARN/System.err(1515): at android.os.Handler.dispatchMessage(Handler.java:92)
05-03 20:14:01.627: WARN/System.err(1515): at android.os.Looper.loop(Looper.java:123)
05-03 20:14:01.627: WARN/System.err(1515): at android.app.ActivityThread.main(ActivityThread.java:4627)
05-03 20:14:01.627: WARN/System.err(1515): at java.lang.reflect.Method.invokeNative(Native Method)
05-03 20:14:01.606: WARN/System.err(1515): at android.view.View$PerformClick.run(View.java:8816)
05-03 20:14:01.616: WARN/System.err(1515): at android.os.Handler.handleCallback(Handler.java:587)
05-03 20:14:01.627: WARN/System.err(1515): at android.os.Handler.dispatchMessage(Handler.java:92)
05-03 20:14:01.627: WARN/System.err(1515): at android.os.Looper.loop(Looper.java:123)
05-03 20:14:01.627: WARN/System.err(1515): at android.app.ActivityThread.main(ActivityThread.java:4627)
05-03 20:14:01.627: WARN/System.err(1515): at java.lang.reflect.Method.invokeNative(Native Method)
05-03 20:14:01.627: WARN/System.err(1515): at java.lang.reflect.Method.invoke(Method.java:521)
05-03 20:14:01.647: WARN/System.err(1515): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-03 20:14:01.647: WARN/System.err(1515): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-03 20:14:01.647: WARN/System.err(1515): at dalvik.system.NativeStart.main(Native Method)
05-03 20:14:01.606: WARN/System.err(1515): at android.view.View$PerformClick.run(View.java:8816)
05-03 20:14:01.616: WARN/System.err(1515): at android.os.Handler.handleCallback(Handler.java:587)
05-03 20:14:01.627: WARN/System.err(1515): at android.os.Handler.dispatchMessage(Handler.java:92)
05-03 20:14:01.627: WARN/System.err(1515): at android.os.Looper.loop(Looper.java:123)
05-03 20:14:01.627: WARN/System.err(1515): at android.app.ActivityThread.main(ActivityThread.java:4627)
05-03 20:14:01.627: WARN/System.err(1515): at java.lang.reflect.Method.invokeNative(Native Method)
05-03 20:14:01.627: WARN/System.err(1515): at java.lang.reflect.Method.invoke(Method.java:521)
05-03 20:14:01.647: WARN/System.err(1515): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-03 20:14:01.647: WARN/System.err(1515): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-03 20:14:01.647: WARN/System.err(1515): at dalvik.system.NativeStart.main(Native Method)
05-03 20:14:01.627: WARN/System.err(1515): at java.lang.reflect.Method.invoke(Method.java:521)
05-03 20:14:01.647: WARN/System.err(1515): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-03 20:14:01.647: WARN/System.err(1515): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-03 20:14:01.647: WARN/System.err(1515): at dalvik.system.NativeStart.main(Native Method)