嗨,我有这个代码。
NSString *urlToAuthPage = [[NSString alloc] initWithFormat:@"&name=%@&street=%@&city=%@&state=%@&zip=%@&lat=%@&lon=%@&hash=%@", name, street, city, state, zip, str1, str2, hash];
NSData *postData = [urlToAuthPage dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:NO];
NSString *postLength = [NSString stringWithFormat:@"%d",[urlToAuthPage length]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://oo.mu/partyapp/post-party.php"]]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
NSString *infoString = [NSString stringWithFormat:@"http://oo.mu/partyapp/post-party.php?name=%@&street=%@&city=%@&state=%@&zip=%@&lat=%@&lon=%@&hash=%@", name, street, city, state, zip, str1, str2, hash];
NSURL *infoUrl = [NSURL URLWithString:infoString];
NSData *infoData = [NSData dataWithContentsOfURL:infoUrl];
NSError *error;
responseDict = [NSJSONSerialization JSONObjectWithData:infoData options:0 error:&error];
NSLog(@"%@", responseDict);
您可能注意到我有一些我知道的不需要的代码,但我对其他东西却得到了错误的响应。如何清理一些代码并从带有 urlToAuthPage 的请求中获取响应?