我是iphone技术的新手,任何人都可以提供帮助,我想使用POST方法向服务器发送JSON数据。
任何人都可以通过提供一些简单的示例应用来帮助我
答案 0 :(得分:1)
您必须使用NSUrlConnection
来完成这项工作。
已经很好地解释了Question
您必须在NSUrlRequest
中将JSON数据设置为http Body
还有其他工具包,如ASIHTTPRequest(已废弃但现在也广泛使用),RestKit等。
答案 1 :(得分: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];