0

I am using AFNetworking to sent a post request to a sever, the request is successful, but no data were sent to the server. the response string is the html form itself and the form is filled in the value i sent to the sever.

Here is the code

 NSURL *url = [NSURL URLWithString:@"http://www.example.com"];
 AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:url];

 NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:
                            @"", @"__EVENTTARGET",
                            @"", @"__EVENTARGUMENT",
                            @"", @"__LASTFOCUS",
                            self.VIEWSTATE, @"__VIEWSTATE",
                            self.subject.text, @"ctl00$ContentPlaceHolder1$messagesubject",
                            self.message.text, @"ctl00$ContentPlaceHolder1$messagetext",
                            @"yes", @"ctl00$ContentPlaceHolder1$btn_Submit",
                            nil];
[httpClient postPath:@"/post.aspx" parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) {

        NSString *responseStr = [[NSString alloc] initWithData:operation.responseData encoding:NSUTF8StringEncoding];

        NSLog(@"Request Successful, response '%@'", responseStr);

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

        NSLog(@"[HTTPClient Error]: %@", error.localizedDescription);            

    }];

any idea?

icodebuster
  • 8,890
  • 7
  • 62
  • 65
  • Can you `NSLog` the params dictionary – icodebuster Jul 14 '13 at 05:34
  • Have a look at this answer. http://stackoverflow.com/questions/17492327/restfull-architecture-http-get-put-requests/17492341#17492341 – Ayush Jul 14 '13 at 06:04
  • to ayush, I try it, but it's still the same – JackKnight Jul 14 '13 at 06:28
  • to icodebuster, here is the NSLog of params dictionary { "__EVENTARGUMENT" = ""; "__EVENTTARGET" = ""; "__LASTFOCUS" = ""; "__VIEWSTATE" = "/wEPDwUJNDI4ODkwMzc4D2QWAmYPZBYEZ......."; "ctl00$ContentPlaceHolder1$messagesubject" = "test_Subject"; "ctl00$ContentPlaceHolder1$messagetext" = "test_message"; "ctl00$ContentPlaceHolder1$btn_Submit" = yes; } – JackKnight Jul 14 '13 at 06:29
  • @JackKnight Then there is issue on server side can you put your server code also. – Ayush Jul 14 '13 at 06:47
  • 1
    What format and headers are you sending and ar expected? – Wain Jul 14 '13 at 07:23
  • 1
    An example of @Wain's comment: some servers require the `Accept` header describe the type of content you want back; AFNetworking does not send this by default. You might also want to look at the AFHTTPRequestOperationLogger extension so you can more easily see what you're sending and receiving. – Aaron Brager Jul 15 '13 at 00:42

0 Answers0