你可以做一些類似發送一個簡單的POST請求使用JSON數據的東西
-(void)sendPostData{
NSString *urlStr = @"http://me.com";
urlStr = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *url = [NSURL URLWithString:urlStr];
NSDictionary* info = [NSDictionary dictionaryWithObjectsAndKeys:user.userName,@"username",user.password,@"password",user.email,@"email", nil];
NSError *error;
NSData* bodyData = [NSJSONSerialization dataWithJSONObject:info
options:kNilOptions error:&error];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:@"POST"];
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:data];
[request setValue:[NSString stringWithFormat:@"%d", [data length]] forHTTPHeaderField:@"Content-Length"];
[NSURLConnection sendAsynchronousRequest:request
queue:[NSOperationQueue mainQueue]
completionHandler:^(NSURLResponse *responseFromRequest, NSData *data, NSError *error)
{
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse*)responseFromRequest;
NSInteger code = [httpResponse statusCode];
}];
}
什麼結果ü需要,ü需要JSON數據發送到http://192.168.1.122/~test/sample /index.php/Api/signup –
是的,我想發送JSON數據到這個URL。請幫助我 –
如果你不是我的可以給你json == { Signup = {0} {0}} {email} = test; password = 123; username = test; }; } ---->此網址 –