Search code examples
iosobjective-chttprequestnsurlconnectiondelegate

NSURLConnetion get access denied response [ios]


I got a problem when I was trying to implement NSURLConnetion. I want to send image and GPS data from mobile side to server and get response from it. My app works perfectly on wifi, but when I try to send data through mobile cellular or 3G. It cannot work. When I log out the response data, and it is a html page and shows that access denied. I don't know why this happened, would anyone give me some ideas, thanks in advance!

What is more, I tried to log out status code and it was 200, so I think the connection is success.

[self.request setAllowsCellularAccess:YES]; // Allow app to use celluar to send data
[self.request setHTTPMethod: @"POST"];
[self.request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[self.request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
[self.request setHTTPBody: self.requestData];

self.connectionStatus.text = @"Data Sending";
[self.connection start];

- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
self.connectionStatus.text = @"Transition complete";

NSString *serverResult = [self.responseFromServer objectForKey:@"result"];

NSString *r = [[NSString alloc] initWithData:_responseData encoding:NSUTF8StringEncoding];
NSLog(@"%@",r);

if([serverResult isEqualToString:@"true"])
{
    [self navigateToMainPage];
    [self.loadingIcon stopAnimating];
}
else
{
    [self.noImageMatchedAlert show];
    [self.loadingIcon stopAnimating];
}

The HTML code below is the response from server

!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

    <title></title>

    <link rel="stylesheet" type="text/css" href="css/default.css" />

    <div id="title">

            </th>
    </div>

    <div id="main">

            <p id="summary">

                    No Entry

                    <img src="images/noEntry.jpg" alt="(-)" />
            </p>
            <p>Access denied.</p>
    </div>


Solution

  • Finally, I found out that the issue was Vodafone network. As you can see below:

    "You acknowledge that the Services may not be available to you in the event that you are denied access or unable to access the internet or this Site. Vodafone shall not be responsible for your inability to use the Services in these circumstances.”

    “The quality and availability of the Vodafone mobile telephony service is subject to certain limitations which may also affect the provision of the Chat Services. The suspension or termination of your Vodafone mobile telephony service account for any reason shall also lead to the suspension or termination of the Chat Services. If you use the Chat Services via the internet, you acknowledge that the Chat Services may not be available to you in the event that you are denied access to or unable to access the internet or this Site for reasons beyond Vodafone’s control. Vodafone shall not be responsible for your inability to use the Service in these circumstances.”