尝试:
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://admin.poslavu.com/cp/reqserv/"]];
[request setValue:@"gzip" forHTTPHeaderField:@"Accept-Encoding"];
[request setHTTPBody:[[NSString stringWithFormat:@"dataname=tangere_techno&key=dBkeY&token=dBt0kEn&table=menu_groups"] dataUsingEncoding:NSUTF8StringEncoding]];
[request setHTTPMethod:@"POST"];
NSError *error = nil; NSURLResponse *response = nil;
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
if (error) {
NSLog(@"Error:%@", error.localizedDescription);
}
else {
//success
}
数据应该是您的 XML 信息,但您需要先对其进行解析。您应该尝试查看 Apple 的文档以获取更多信息。如果您尝试异步发出请求,请尝试以下操作:
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://admin.poslavu.com/cp/reqserv/"]];
[request setValue:@"gzip" forHTTPHeaderField:@"Accept-Encoding"];
[request setHTTPBody:[[NSString stringWithFormat:@"dataname=tangere_techno&key=dBkeY&token=dBt0kEn&table=menu_groups"] dataUsingEncoding:NSUTF8StringEncoding]];
[request setHTTPMethod:@"POST"];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:req];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject){
NSData *data = (NSData *)responseObject;
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
[operation start];