由“302暂时移动”引起的Android ClientProtocolException

时间:2015-02-07 00:52:57

标签: java android http exception

这是我的示例代码。我得到 ClientProtocolException 由“无效标题:HTTP / 1.1 302暂时移动”引起

        HttpPost httpPost = new HttpPost(this.INDEX_URL);
        httpPost.setHeader("Accept-Encoding", "gzip, deflate");
        httpPost.setHeader("Cookie", "sessionid=75687df9; language=en_us; sys_UserName=1234");
        httpPost.setHeader("Content-Type", "application/x-www-form-urlencoded");
        httpPost.setHeader("Referer", "http://192.168.1.1:8000/cgi-bin/webproc");

        List<NameValuePair> nameValuePairs = new ArrayList<>(8);
        nameValuePairs.add(new BasicNameValuePair("getpage", "html/index.html"));
        nameValuePairs.add(new BasicNameValuePair("errorpage", "html/main.html"));
        nameValuePairs.add(new BasicNameValuePair("var:menu", "setup"));
        nameValuePairs.add(new BasicNameValuePair("var:page", "wizard"));
        nameValuePairs.add(new BasicNameValuePair("obj-action", "auth"));
        nameValuePairs.add(new BasicNameValuePair(":username", "1234"));
        nameValuePairs.add(new BasicNameValuePair(":password", "1234"));
        nameValuePairs.add(new BasicNameValuePair(":action", "login"));
        nameValuePairs.add(new BasicNameValuePair(":sessionid", "75687df9"));

        httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

        //Execute post request
        HttpResponse response = this.client.execute(httpPost);

调试:

02-09 21:54:48.123    1886-2361/com.armstar.dsltester W/System.err﹕ org.apache.http.client.ClientProtocolException
02-09 21:54:48.130    1886-2361/com.armstar.dsltester W/System.err﹕ at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:557)
02-09 21:54:48.130    1886-2361/com.armstar.dsltester W/System.err﹕ at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
02-09 21:54:48.130    1886-2361/com.armstar.dsltester W/System.err﹕ at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
02-09 21:54:48.130    1886-2361/com.armstar.dsltester W/System.err﹕ at com.armstar.dsltester.SigaHttpRequest.requestStatsUrl(SigaHttpRequest.java:76)
02-09 21:54:48.130    1886-2361/com.armstar.dsltester W/System.err﹕ at com.armstar.dsltester.MainActivity$RegisterAsyncTask.doInBackground(MainActivity.java:105)
02-09 21:54:48.130    1886-2361/com.armstar.dsltester W/System.err﹕ at com.armstar.dsltester.MainActivity$RegisterAsyncTask.doInBackground(MainActivity.java:89)
02-09 21:54:48.130    1886-2361/com.armstar.dsltester W/System.err﹕ at android.os.AsyncTask$2.call(AsyncTask.java:288)
02-09 21:54:48.130    1886-2361/com.armstar.dsltester W/System.err﹕ at java.util.concurrent.FutureTask.run(FutureTask.java:237)
02-09 21:54:48.130    1886-2361/com.armstar.dsltester W/System.err﹕ at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
02-09 21:54:48.130    1886-2361/com.armstar.dsltester W/System.err﹕ at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
02-09 21:54:48.130    1886-2361/com.armstar.dsltester W/System.err﹕ at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
02-09 21:54:48.138    1886-2361/com.armstar.dsltester W/System.err﹕ at java.lang.Thread.run(Thread.java:841)
02-09 21:54:48.138    1886-2361/com.armstar.dsltester W/System.err﹕ Caused by: org.apache.http.ProtocolException: Invalid header: HTTP/1.1 302 Moved Temporarily
02-09 21:54:48.138    1886-2361/com.armstar.dsltester W/System.err﹕ at org.apache.http.impl.io.AbstractMessageParser.parseHeaders(AbstractMessageParser.java:162)
02-09 21:54:48.138    1886-2361/com.armstar.dsltester W/System.err﹕ at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:178)
02-09 21:54:48.138    1886-2361/com.armstar.dsltester W/System.err﹕ at org.apache.http.impl.AbstractHttpClientConnection.receiveResponseHeader(AbstractHttpClientConnection.java:180)
02-09 21:54:48.138    1886-2361/com.armstar.dsltester W/System.err﹕ at org.apache.http.impl.conn.DefaultClientConnection.receiveResponseHeader(DefaultClientConnection.java:235)
02-09 21:54:48.138    1886-2361/com.armstar.dsltester W/System.err﹕ at org.apache.http.impl.conn.AbstractClientConnAdapter.receiveResponseHeader(AbstractClientConnAdapter.java:259)
02-09 21:54:48.138    1886-2361/com.armstar.dsltester W/System.err﹕ at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:279)
02-09 21:54:48.138    1886-2361/com.armstar.dsltester W/System.err﹕ at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:121)
02-09 21:54:48.138    1886-2361/com.armstar.dsltester W/System.err﹕ at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:428)
02-09 21:54:48.138    1886-2361/com.armstar.dsltester W/System.err﹕ at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
02-09 21:54:48.138    1886-2361/com.armstar.dsltester W/System.err﹕ ... 11 more

我正在寻找谷歌,stackoverflow的答案,但没办法。有解决方案吗?提前致谢!

0 个答案:

没有答案