0

我是 iphone 技术的新手,谁能帮忙,我想使用 POST 方法将 JSON DATA 发送到服务器。

任何人都可以通过提供一些简单的示例应用程序来帮助我吗

4

2 回答 2

1

你必须利用NSUrlConnection 这项工作。所以已经有一个很好解释的问题 你必须将你的 JSON 数据设置为 http Body 中NSUrlRequest 还有其他工具包,如 ASIHTTPRequest(已被废弃但现在也被广泛使用)、RestKit 等。

于 2012-10-03T18:41:02.177 回答
0
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:requestUrlString]];
    NSMutableDictionary *dict1 =[[NSMutableDictionary alloc] init];
    if ([m_ProductInfoDictonary objectForKey:@"TOKEN"] != nil) {
        [dict1 setObject:[mAppDelegate.m_ProductDictonary objectForKey:@"TOKEN"] forKey:@"token"];
NSMutableDictionary *dict2 =[[NSMutableDictionary alloc] init];
    [dict2 setObject:[mAppDelegate.m_ProductDictonary objectForKey:@"PRODUCTNAME" ] forKey:@"title"];
    [dict2 setObject:[mAppDelegate.m_ProductDictonary objectForKey:@"DESCRIPTION" ] forKey:@"description"];
    [dict2 setObject:[mAppDelegate.m_ProductDictonary objectForKey:@"PRODUCTPRICE" ] forKey:@"price"];
    [dict2 setObject:[mAppDelegate.m_ProductDictonary objectForKey:@"ZIPCODE" ]forKey:@"zipcode"];
NSMutableDictionary *dict =[[NSMutableDictionary alloc] init];
    [dict setObject:dict2 forKey:@"item"];
    [dict setObject:dict1 forKey:@"user"];
    //[dict setObject:dict3 forKey:@"item_images"];
    [dict1 release];
    [dict2 release];
[request setPostValue:[dict JSONRepresentation] forKey:@"item_post"];
[request setPostFormat:ASIMultipartFormDataPostFormat];
[request setTimeOutSeconds:200];
[request setDelegate:self];

[request setDidFinishSelector:@selector(uploadRequestFinished:)];
[request setDidFailSelector:@selector(uploadRequestFailed:)];

[request startSynchronous];
[requestUrlString release];
于 2012-10-03T18:50:02.130 回答