如何使用iOS应用程序的Web服务器? 样本

我写了类似的问题,我回答了“如何使用iOS应用程序的Web服务器? 但我需要样本,因为它是更简单的,我有一些示例如何工作,例如,你可以帮助我的样本:

我怎么能实现请求在我的服务器exhample如果我想/注册新用户,我会收到服务器的答案在JSON中,我需要发送它variables'数据'POST? 对于exhample服务器是http://myserver.com:8080 。

{ email: password: } //this is register form but how named this field? 

我将会收到这样的答复:

 { result:[OK|fail] message: [error if fail] data: [if OK] } 

我需要样本如何发送和接收/注册请求。 对不起,我的英文,它变得更好:)

更新我也不明白我怎么能在Objective-C中使用这个表单?

所以,在这里你有我的寺庙发送loginreq,我已经实施AFNetworking( https://github.com/AFNetworking/AFNetworking )和NSJSONSerializationparsingJson响应。 很难给你一个示例代码,但我认为如果你定制这段代码,一切都应该正常工作。

  - (void)sentLoginReqWithLogin:(NSString *)email andPassword:(NSString *)pass { NSDictionary *params = @{@"email" : email, @"password" : pass }; AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:[NSURL URLWithString:HOST_URL]]; NSMutableURLRequest *request = [httpClient requestWithMethod:POST path:LOGIN_URL parameters:params]; AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request]; [httpClient registerHTTPOperationClass:[AFHTTPRequestOperation class]]; [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) { NSLog(@"Response: %@", [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding]); NSDictionary *response = (NSDictionary*)[NSJSONSerialization JSONObjectWithData:operation.responseData options:kNilOptions error:nil]; //HERE YOU HAVE A RESPONSE (your server answer) } failure:^(AFHTTPRequestOperation *operation, NSError *error) { NSLog(@"Error: %@", error); }]; [operation start]; } 
 // Post data to server NSURL * url = [NSURL URLWithString:@"http://myserver.com/register/"]]; NSMutableURLRequest * request = [[NSMutableURLRequest alloc] initWithURL:url]; [request setHTTPMethod:@"POST"]; NSString * bodyString = [NSString stringWithFormat:@"&username=%@&password=%ld", "username", "password"]; [request setHTTPBody:[bodyString dataUsingEncoding:NSASCIIStringEncoding]]; NSURLConnection * urlConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES]; // On server, do this (assuming PHP) $username = $_REQUEST['username']; $password = $_REQUEST['password']; // Do w/e checks you need to do against the username and password, be sure to hash and salt the password // Store user information in database