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>