NSURLConnection POST also calls GET of the same URL

I have NSURLConnection, which is mail on the server, but I expect it to return some small data, whether it is successful or not.

-(void)submitPost:(NSString *)xml { NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[service generateURL]]; NSString *result = (NSString *) CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (CFStringRef)xml, NULL, CFSTR("?=&+"), kCFStringEncodingUTF8); [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"]; [request setHTTPBody:[result dataUsingEncoding:NSUTF8StringEncoding]]; [request setHTTPMethod:@"POST"]; NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:request delegate:self]; if(theConnection) { NSLog(@"Connection success"); [UIApplication sharedApplication].networkActivityIndicatorVisible = YES; [theConnection retain]; failed = NO; } else { NSLog(@"Connection failed"); } } 

The problem is not only that it sends a URL message, but also sends a GET, and the GET response is returned as data ... I'm a bit confused. I checked the output of my wires, and it definitely does both the message and the receipt.

What do you guys think?

+4
source share
1 answer

Does the POST URL respond with a redirect? You can implement the NSURLConnection connection:willSendRequest:redirectResponse: delegate method to find out if this is the case (and cancel the unwanted redirect).

+8
source

Source: https://habr.com/ru/post/1305868/


All Articles