android http设置body,HTTP body post in android

I am new to android development. In my application I have to use HTTP body post. But I'm getting an error.

Here is my code:

HttpClient httpclient = new DefaultHttpClient();

HttpPost httppost = new HttpPost("http://67.64.238.61:8182/websearch");

try {

StringEntity se = new StringEntity( "testtest1234567890", 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();

}

I am getting this kind of error:

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值