0

I am working on an iOS app which interacts with a remote WS. As the URL of the WS might change from time to time, the app should send all the requests to a fixed and stable URL which takes care of redirecting them to the actual URL of the WS.

Here is my code:

- (NSURLRequest *)connection: (NSURLConnection *)connection
         willSendRequest: (NSURLRequest *)request
        redirectResponse: (NSURLResponse *)redirectResponse {

if (redirectResponse) {
    NSMutableURLRequest *r = [lastRequest mutableCopy];
    [r setURL: [request URL]];

    return r;
} else {
    return request;
}
}

where lastRequest is a copy of the original request that has been sent.

Here is my problem: I don't know why but the new request, that is r, is sent with an empty body (no parameters). Looks like all the parameters of the original request are lost, even if I use an exact copy of the original request.

What do you guys think? How could I fix this problem?

Thanks!

pAkY88
  • 6,262
  • 11
  • 46
  • 58

1 Answers1

0

I think that the problem is related to the fact that, according to HTTP standards, a redirected request should use the GET method, so the request body is empty.

I solved the problem by returning nil instead of r and generating a new request with the right URL.

pAkY88
  • 6,262
  • 11
  • 46
  • 58