2012-10-03 93 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];