Whenever I attempt to post something to my PHP Server, I receive the following message. It seems as if the code is connecting to the server, but no data is returned, and the post data isn't going through. It worked through a Java App that I made, so I can assure that their is nothing wrong with my PHP. If you could help me, or need any more code to help me, just ask for it. Thanks.
Here is the code that prepares my variables for the NSURLConnection:
NSString *phash = [NSString stringWithFormat:@"%d",phashnum];
[phash stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
name = _nameField.text;
[name stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
email = _emailField.text;
[email stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
Here is the code for my NSURLConnection:
NSString *urlPath = [NSString stringWithFormat:@"http://54.221.224.251"];
NSURL *url = [NSURL URLWithString:urlPath];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
NSString *stringdata = [NSString stringWithFormat:@"name=%@&email=%@&phash=%@",name,email,phash];
NSOperationQueue *queue= [[NSOperationQueue alloc]init];
NSString *postData = [[NSString alloc] initWithString:stringdata];
[request setValue:@"application/x-www-form-urlencoded; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[request setHTTPMethod:@"POST"];
[request setHTTPBody:[postData dataUsingEncoding:NSUTF8StringEncoding]];
[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
if ([data length] > 0 && connectionError==nil){
NSLog(@"Connection Success. Data Returned");
NSLog(@"Data = %@",data);
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
int code = [httpResponse statusCode];
NSString *coder = [NSString stringWithFormat:@"%d",code];
NSLog(@"%@",coder);
}
else if([data length] == 0 && connectionError == nil){
NSLog(@"Connection Success. No Data returned.");
NSLog(@"Connection Success. Data Returned");
NSLog(@"Data = %@",data);
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
int code = [httpResponse statusCode];
NSString *coder = [NSString stringWithFormat:@"%d",code];
NSLog(@"%@",coder);
}
else if(connectionError != nil && connectionError.code == NSURLErrorTimedOut){
NSLog(@"Connection Failed. Timed Out");
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
int code = [httpResponse statusCode];
NSString *coder = [NSString stringWithFormat:@"%d",code];
NSLog(@"%@",coder);
}
else if(connectionError != nil)
{
NSLog(@"%@",connectionError);
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
int code = [httpResponse statusCode];
NSString *coder = [NSString stringWithFormat:@"%d",code];
NSLog(@"%@",coder);
}
}];
Thanks in advance.