我查了很多关于http帖子请求的帖子,但我仍然无法找到答案。我的问题是我需要将一个字符串发送到我的工作伙伴网站,以便可以使用GET请求访问它并用于排行榜/
NSMutableURLRequest *req = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:url]];
[req setHTTPMethod:@"POST"];
NSData *postData = [revs dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%d",[postData length]];
[req addValue:postLength forHTTPHeaderField:@"Content-Length"];
[req setHTTPBody:postData];
NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *task = [session dataTaskWithRequest:req
completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
// Do something with response data here - convert to JSON, check if error exists, etc....
NSLog(response.description);
// NSLog([[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding]);
}];
[task resume];
但请求永远不会进入网站,它被称为../ distances.txt
有人可以帮忙吗?