2011-05-21 144 views
0

我想用POST/PUT发送JSON我不知道它是否一样。 这是json。 {“author”:“mehdi”,“email”:“[email protected]”,“message”:“Hello2”} 这是我的wadl。用POST发送JSON到Restful web服务

<resource path="/messages/"><method id="get" name="GET"><request><param name="start" style="query" type="xs:int" default="0"/><param name="max" style="query" type="xs:int" default="10"/><param name="expandLevel" style="query" type="xs:int" default="1"/><param name="query" style="query" type="xs:string" default="SELECT e FROM Message e"/></request><response><representation mediaType="application/xml"/><representation mediaType="application/json"/></response></method><method id="post" name="POST"><request><representation mediaType="application/xml"/><representation mediaType="application/json"/></request><response><representation mediaType="*/*"/></response></method><resource path="{keyid}/"><param name="keyid" style="template" type="xs:int"/><method id="get" name="GET"><request><param name="expandLevel" style="query" type="xs:int" default="1"/></request><response><representation mediaType="application/json"/></response></method></resource></resource> 

当我特里树后与NetBeans “测试RESTful Web服务” 它的工作,这是笏HTTP监视器显示

状态:201(创建)

时间标签:星期六2011年5月21日二十点30分33秒 GMT

发送: { “作者”: “迈赫迪”, “电子邮件”: “[email protected]”, “消息”: “Hello2”}

收稿日期:


请求:POST http://localhost:8080/TRESTful/resources/messages/? 时间戳= 1306009225785

状态:201(创建)

时间标记:星期六,2011 5月21日20时20分25秒 GMT

发送: { “作者”: “迈赫迪” “电子邮件”: “[email protected]”, “消息”: “Hello2”}

但现在我不知道。首先应该ASIHttpRequest如何我做[要求setRequestMethod:@ “PUT”]; ?和我应该把所有的JSON像绳子,或把每个值与哎键,这样的:

ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url]; 
[request setPostValue:@"Ben" forKey:@"author"]; 
[request setPostValue:@"Copsey" forKey:@"email"]; 
[request setPostValue:@"Hello2" message:@"author"]; 
[request startSynchronous]; 

或者我应该把JSON字符串中的一个值?

请帮忙。

回答

2

那么,如果你想送一个JSON你有两种选择:

一)发送一个文件 - 使用此,如果你在一个JSON有大量的数据,你可能想存储它服务器供以后解析。

b)将它作为字符串中的一个值 - 使用此,如果您的JSON是短,你要分析它立即

编辑

C)将其作为单独的值,如果你想跳过服务器上的解析并直接访问数据。如果数据很少,这应该被使用。

+0

非常感谢 – user567 2011-05-22 03:22:51