我是android开发的新手。在我的应用程序中,我必须使用 HTTP 正文帖子。但我遇到了一个错误。
这是我的代码:
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://67.64.238.61:8182/websearch");
try {
StringEntity se = new StringEntity( "<Search><Login><User>test</User><Password>test</Password></Login><SearchWord>1234567890</SearchWord><NextToken></NextToken></Search>", HTTP.UTF_8);
se.setContentType("text/xml");
httppost.setEntity(se);
//HttpResponse httpresponse = httpclient.execute(httppost);
BasicHttpResponse httpResponse = (BasicHttpResponse) httpclient .execute(httppost);
HttpEntity resEntity = httpResponse.getEntity();
String str = EntityUtils.toString(resEntity);
System.out.println("==="+str);
//tvData.setText(EntityUtils.toString(resEntity));
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
我收到这种错误:
06-08 16:25:38.665: WARN/System.err(12122): org.apache.http.client.ClientProtocolException
06-08 16:25:38.665: WARN/System.err(12122): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:557)
06-08 16:25:38.665: WARN/System.err(12122): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
06-08 16:25:38.675: WARN/System.err(12122): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
06-08 16:25:38.675: WARN/System.err(12122): at com.texas.book.Search.search(Search.java:225)
06-08 16:25:38.675: WARN/System.err(12122): at com.texas.book.Search$Progress.doInBackground(Search.java:196)
06-08 16:25:38.675: WARN/System.err(12122): at com.texas.book.Search$Progress.doInBackground(Search.java:1)
06-08 16:25:38.675: WARN/System.err(12122): at android.os.AsyncTask$2.call(AsyncTask.java:185)
06-08 16:25:38.675: WARN/System.err(12122): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
06-08 16:25:38.675: WARN/System.err(12122): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
06-08 16:25:38.675: WARN/System.err(12122): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
06-08 16:25:38.685: WARN/System.err(12122): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
06-08 16:25:38.685: WARN/System.err(12122): at java.lang.Thread.run(Thread.java:1096)
06-08 16:25:38.685: WARN/System.err(12122): Caused by: org.apache.http.ProtocolException: Unable to parse status code from status line: HTTP/1.1 ñðð@ã¤
06-08 16:25:38.685: WARN/System.err(12122): at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:176)
06-08 16:25:38.685: WARN/System.err(12122): at org.apache.http.impl.AbstractHttpClientConnection.receiveResponseHeader(AbstractHttpClientConnection.java:179)
06-08 16:25:38.685: WARN/System.err(12122): at org.apache.http.impl.conn.DefaultClientConnection.receiveResponseHeader(DefaultClientConnection.java:235)
06-08 16:25:38.695: WARN/System.err(12122): at org.apache.http.impl.conn.AbstractClientConnAdapter.receiveResponseHeader(AbstractClientConnAdapter.java:259)
06-08 16:25:38.695: WARN/System.err(12122): at org.apache.http.protocol.HttpRequestExecutor.doSendRequest(HttpRequestExecutor.java:219)
06-08 16:25:38.695: WARN/System.err(12122): at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:119)
06-08 16:25:38.695: WARN/System.err(12122): at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:410)
06-08 16:25:38.695: WARN/System.err(12122): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
06-08 16:25:38.695: WARN/System.err(12122): Caused by: org.apache.http.ParseException: Unable to parse status code from status line: HTTP/1.1 ñðð@ã¤
06-08 16:25:38.715: WARN/System.err(12122): at org.apache.http.message.BasicLineParser.parseStatusLine(BasicLineParser.java:424)
06-08 16:25:38.715: WARN/System.err(12122): at org.apache.http.impl.conn.DefaultResponseParser.parseHead(DefaultResponseParser.java:99)
06-08 16:25:38.715: WARN/System.err(12122): at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:174)
06-08 16:25:38.715: WARN/System.err(12122): ... 18 more