2

Sorry, but im kinda a newb regarding http post terminology!

I have to post to a webservice that cannot be changed: The format is as follows:

http://SomeWebAddress/JSON/GetAllFeedsRestfullyWrapped?userToken=FOO             

so the parameters are:

key:userToken , value=FOO

In the body i need to put a JSON formatted array like this:

{"feedIds":[1,2,3,4,5,6]}

Im trying to accomplish this with AFNetworking but cannot seem to make it work for this situation.

I have tried both the AFHttpclient and AFJSONReqestIOperation but im not able to combine the request and body correct.

So i hope someone knows how to do this. Help is very much appreciated.

ThBlitz
  • 493
  • 4
  • 17

2 Answers2

2

Try that

[[YourHTTPClient sharedHTTPClient] postPath:@"GetAllFeedsRestfullyWrapped?userToken=FOO"
                              parameters:[NSDictionnary {"feedIds":[1,2,3,4,5,6]}]
                                 success:^(AFHTTPRequestOperation *request, id JSON)
 {

 }
                                 failure:^(AFHTTPRequestOperation *request, NSError *error)
 {

 }];
Mathieu Hausherr
  • 3,485
  • 23
  • 30
  • Thanks. This setup worked, when changing getPath to postPath. Ill put my own real code as an answer. Sorry but i cannot upvote your response yet. (low rep:-() – ThBlitz Jun 04 '12 at 18:06
1

So using Mathieu Hausherr's response as a baseline this was my solution:

NSArray *feedIds = [NSArray arrayWithObject:[NSNumber numberWithInteger:3]];
NSMutableDictionary *parameters = [[NSMutableDictionary alloc]init];
[parameters setObject:feedIds forKey:@"listOfFeedIds"];    
[[RssReaderWebserviceApiClient sharedInstance] postPath:@"GetFeedsRestfullyWrapped?userToken=FOO"
                                             parameters:parameters
                                                success:^(AFHTTPRequestOperation *request, id JSON){
                                                    LOG_TEST(1,@"Response: %@",JSON);
                                                }
                                                failure:^(AFHTTPRequestOperation *request, NSError *error){
                                                    LOG_ERROR(1,@"Error: %@",error);
                                                }];

I use the method postPath:parameters to achieve the post.
I manually set the parameters in the request header and input the bodyparameters from a dictionary.
Encoding is set to JSON.
I anyone wonders the logging is done using NSLogging.It's awesome.

ThBlitz
  • 493
  • 4
  • 17