现在在做一个android应用,http是用httpclient接口实现的。
现在Get方法没问题,但是Post方法有点不懂。如发表一条豆瓣说POST http://api.douban.com/miniblog/saying<?xml version='1.0' encoding='UTF-8'?>
<entry xmlns:ns0="http://www.w3.org/2005/Atom" xmlns:db="http://www.douban.com/xmlns/">
<content>收拾屋子就是把书从床头搬到书架的过程</content>
</entry>现在是把xml数据转变为StringEntity来发送,但是状态返回为400。想问一下有谁用httpclient的,xml数据应该怎样设置?
现在Get方法没问题,但是Post方法有点不懂。如发表一条豆瓣说POST http://api.douban.com/miniblog/saying<?xml version='1.0' encoding='UTF-8'?>
<entry xmlns:ns0="http://www.w3.org/2005/Atom" xmlns:db="http://www.douban.com/xmlns/">
<content>收拾屋子就是把书从床头搬到书架的过程</content>
</entry>现在是把xml数据转变为StringEntity来发送,但是状态返回为400。想问一下有谁用httpclient的,xml数据应该怎样设置?
解决方案 »
- 求高手指导,毕业论文抽到“基于Android 平台的特定网站客户端的设计与实现”这个题目,全部没有头绪
- 怎么写才能让apk在安装的时候不在Launcher显示图标而且可以接受开机启动广播
- 请教手动接受GPS数据
- 如何是运行的游戏暂停。
- 不能通过Android虚拟器访问任何网页
- ant打包android项目出现No resource found that matches the given name
- 初学安卓不久, 请教各位大侠。关于视频播放器
- android 通过soap协议下载文件
- 安卓遍历数据库,条件是整形的呀。rawquery()只能用string的怎么办
- Android获取后台正在运行的程序问题
- android开发中怎样在浮动搜索框搜索的结果放在LISTVIEW内??
- 在真机中,用mapView开发出来的地图背景变为黑色
void testPost() throws IOException, OAuthException {
OAuthConsumer consumer = new DoubanOAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET);
consumer.setTokenWithSecret(ACCESS_TOKEN, ACCESS_TOKEN_SECRET);
String url = "http://api.douban.com/miniblog/saying";
HttpPost request = new HttpPost(url);
String say = "<?xml version='1.0' encoding='UTF-8'?>" +
"<entry xmlns:ns0=\"http://www.w3.org/2005/Atom\" xmlns:db=\"http://www.douban.com/xmlns/\">" +
"<content>test from jxphone-douban</content>" +
"</entry>";
StringEntity entity = new StringEntity(say, HTTP.UTF_8);
entity.setContentType("text/xml");
request.setHeader("Content-Tyep", "application/atom+xml");
request.setEntity(entity);
consumer.sign(request);
HttpClient client = new DefaultHttpClient();
HttpResponse response = client.execute(request);
System.out.println(response.getStatusLine().getStatusCode() + "");
}