2012-03-30 23 views
0

WebServiceに何かをアップロードする方法に疑問があります。私は自分のWebサービスから情報を取得するためにこれを使用してきたWebServiceに配列をアップロードする方法

NSString * URLString = [NSString stringWithFormat:@"%@%@", kBaseHost, [NSString stringWithFormat:kWSProjectList, token]]; 
NSURL *url = [NSURL URLWithString:URLString]; 
NSURLRequest * request = [NSURLRequest requestWithURL:url]; 
[NSURLConnection sendSynchronousRequest:request inBackgroundWithCompletionHandler:^(NSURLResponse *response, NSData *data, NSError *error) { 
    NSString *json = [[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding]; 
    NSLog(@"%@", json); 
    NSDictionary * _response = [json JSONValue]; 
    NSLog (@"%@", _response); 
    NSNotification* notification = [NSNotification notificationWithName:kWSNotificationDidReceiveDataProjectList object:_response]; 
    [[NSNotificationCenter defaultCenter] postNotification:notification]; 
}]; 

今、私は反対のことをしなければならない、私は、Webサービスに情報をアップロードする必要があり、私はどのようのないアイデアを持っていません。..誰かが私を少し導くことができましたか?

+0

この方法、sendSynchronousRequestどのようなものです:inBackgroundWithCompletionHandler:私は、ドキュメント内の1つが表示されていない – rdelmar

+0

@interface NSURLConnection(背景) +(無効)sendSynchronousRequest:(NSURLRequest *)要求がinBackgroundWithCompletionHandler:(void(^)(NSURLResponse *、NSData *、NSError *))ハンドラ。 – Marnerk

答えて

0

JSONを使用している場合は、このようにすることができます。あなたはおそらく何らかのエラーチェックを追加したいと思うかもしれませんが、これはあなたを始めさせるはずです。

-(void)sendArray { 
NSArray *array = <your array here> 
NSData *post = [NSJSONSerialization dataWithJSONObject:array options:NSJSONWritingPrettyPrinted error:nil]; 
NSString *postLength = [NSString stringWithFormat:@"%d", [post length]]; 
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:kServerPath]]; 
[request setHTTPMethod:@"POST"]; 
[request setValue:postLength forHTTPHeaderField:@"Content-Length"]; 
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"]; 
[request setHTTPBody:post]; 
[request setCachePolicy:NSURLRequestReloadIgnoringLocalCacheData]; 
[request setTimeoutInterval:5]; 
NSOperationQueue *queue = [[NSOperationQueue alloc] init]; 
[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse* theResponse, NSData* theData, NSError* error){ 
    //Do whatever with return data 
}]; 

}

関連する問題