1

i tried it but didn't work in AFNetworking only showing parameters error but i used postman to check and when i send data via key and value it showing error but from raw data i send {"register_id":"3"} then it will show me data so how to post parameter like this in AFNetworking.

using This Link

http://www.icubemedia.net/visitorbook/display_all.php

is any one can help me for that how to post that data

log error is:

2015-06-19 14:05:08.078 DemoAFNetworking[72771:1160924] {"msg":"parameter missing!"}

Cœur
  • 37,241
  • 25
  • 195
  • 267
vp2698
  • 1,783
  • 26
  • 28

2 Answers2

1

Indeed there are no parameters missing, the fact that the request worked in Postman was the key. On the one hand, you should be trying to POST to that URL, not GET. On the other hand, since you are sending a JSON, you need the appropriate serializer.

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
//JSON Serializer
manager.requestSerializer = [AFJSONRequestSerializer serializer];
NSDictionary *parameters = @{@"register_id": @"3"};

[manager POST:@"http://www.icubemedia.net/visitorbook/display_all.php" parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
  NSLog(@"JSON: %@", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
  NSLog(@"Error: %@", error);
}];
J.C. Chaparro
  • 1,079
  • 10
  • 13
0

Check this example on how to do a GET with simple parameter with AFNetworking 2.0:

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.requestSerializer = [AFJSONRequestSerializer serializer];
NSDictionary *parameters = @{@"foo": @"bar"};

[manager GET:@"http://example.com/resources.json" parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
    NSLog(@"JSON: %@", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    NSLog(@"Error: %@", error);
}];

EDIT 1: added JSON serializer ;)

Massimo Polimeni
  • 4,826
  • 4
  • 27
  • 54
  • i tried this already but didn't work only showing message that parameter missing – vp2698 Jun 19 '15 at 08:26
  • are you sure that your parameter is called "register_id"? Are you sure that you need only one parameter? – Massimo Polimeni Jun 19 '15 at 08:28
  • But In postman i tried that data with raw data like {"register_id":3} and that show me data but i in xcode this didnt work is there any way to pass json parameters in afnetworking – vp2698 Jun 19 '15 at 08:29
  • can you add at your question your complete log error? – Massimo Polimeni Jun 19 '15 at 08:33
  • 2015-06-19 14:05:08.078 DemoAFNetwoking[72771:1160924] {"msg":"parameter missing!"} – vp2698 Jun 19 '15 at 08:35
  • it's error came from API. i cant understand i had send parameter in correct formate but didn't work – vp2698 Jun 19 '15 at 08:38
  • mm sorry but at the moment I haven't any other ideas. You should check carefully your code because the server reply (so the call is right) to your request but something wrong with parameters. If you're really stuck you can try to do the same request with NSURL maybe – Massimo Polimeni Jun 19 '15 at 08:53
  • You code is Right But only forgot to mention AFJSONRequestSerializer. But thanx for answering – vp2698 Jun 20 '15 at 10:34