我想在Java中使用JSON进行简单的HTTP POST.
我们说URL是 www.site.com
并且它采用{"name":"myname","age":"20"}标记'details'为例如的值.
我将如何创建POST的语法?
我似乎也无法在JSON Javadocs中找到POST方法.
我有这个JSON字符串.我想将它发布到服务器(即使用POST方法).如何在Android中完成?
JSON字符串:
{
"clientId": "ID:1234-1234",
"device": {
"userAgent": "myUA",
"capabilities": {
"sms": true,
"data": true,
"gps": true,
"keyValue": {
"Key2": "MyValue2",
"Key1": "myvalue1"
}
},
"screen": {
"width": 45,
"height": 32
},
"keyValue": {
"DevcKey2": "myValue2",
"DevcKey1": "myValue1"
}
},
"time": 1294617435368
}
Run Code Online (Sandbox Code Playgroud)
如何构建此JSON数组并将其POST到服务器?
我应该如何构建实体以实现此发布请求?
POST https://picasaweb.google.com/data/feed/api/user/userID/albumid/albumID/photoid/photoID
<entry xmlns='http://www.w3.org/2005/Atom'>
<content>great photo!</content>
<category scheme="http://schemas.google.com/g/2005#kind"
term="http://schemas.google.com/photos/2007#comment"/>
</entry>
Run Code Online (Sandbox Code Playgroud)
它来自:http: //code.google.com/intl/zh-TW/apis/picasaweb/docs/2.0/developers_guide_protocol.html#AddComments
有人可以提供示例或任何提示吗?非常感谢.
更新:我在这里添加了我的代码:
List<Header> headers = new ArrayList<Header>();
headers.add(new BasicHeader("GData-Version", "2"));
headers.add(new BasicHeader("Authorization", "GoogleLogin auth=" + mAuthToken));
EntityTemplate entity = new EntityTemplate(new ContentProducer() {
public void writeTo(OutputStream ostream) throws IOException {
Writer writer = new OutputStreamWriter(ostream, "UTF-8");
writer.write("\r\n");
writer.write("<entry xmlns='http://www.w3.org/2005/Atom'>");
writer.write("<content>" + comment + "</content>");
writer.write("<category scheme=\"http://schemas.google.com/g/2005#kind\"\r\n");
writer.write("term=\"http://schemas.google.com/photos/2007#comment\"/>");
writer.write("</entry>\r\n");
writer.flush();
}
});
Run Code Online (Sandbox Code Playgroud)
仍然没有运气.任何的想法?