Reputation: 658
So i'm having a problem posting POST data to my codeigniter controller, but if I have a regular PHP script with $_POST it works, heres my code:
iPhone method:
NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:
[username text],@"username",
nil];
AFHTTPClient *client = [[AFHTTPClient alloc] initWithBaseURL:[NSURL URLWithString:@"http://www.mysite.com/"]];
[client postPath:@"test/text_func" parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSString *response = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
NSLog(@"%@",response);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"%@",[error localizedDescription]);
}];
Codeigniter Controller:
public function test_func() {
echo "Username: " . $this->input->post('username');
}
If I run it from the phone, I will get "Username:" in the log, with no actual username.
But if I make a PHP script on a separate server with:
echo "Username: " . $_POST['username'];
I will get this when I run it from the phone:
"Username: my username"
So I know the iPhone app is POSTing the data, but I can not get the codeigniter controller to read it.
I have made many iphone apps that use AFNetworking without a problem, but never with a codeigniter backend so I have no idea what the problem could be.
I do not have CSRF Protection on.
Any help would be greatly appreciated.
All above code is strictly for testing purposes, and whilst not the real methods, have the same bare bones concept.
Upvotes: 0
Views: 755
Reputation: 658
Ok so the problem was I was missing the 's' in https on the phone url, the website is secure...
Upvotes: 1