2012-10-03 148 views
0

我是iphone技术新手,任何人都可以帮忙,我想用POST方法发送JSON DATA到服务器。Resting with Json post

任何一个可以帮助我,给了一些简单的示例应用程序

+1

您问题不清楚。请添加更多内容。 – Cybermaxs

回答

1

你必须使用NSUrlConnection这项工作。 SO已经有了一个很好的解释Question 必须设置你的JSON数据的HTTP主体在NSUrlRequest 也有其他包诸如ASIHTTPRequest(抛弃,但现在广泛使用的也可以),RestKit等

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];