0

AFNetworking How to send a string of post request?

//restrinBASE64STRING is a NSString ,Program error [manager POST:URLString parameters:restrinBASE64STRING success:^(AFHTTPRequestOperation *operation, id responseObject) { } failure:^(AFHTTPRequestOperation *operation, NSError *error) { }]; 
3
  • By default, AFNetworking assumes the request is a standard application/x-www-form-urlencoded request of the form key1=value1&key2=value2. It can easily use a different request serializer in order to send JSON requests, too. The parameters should not be a simple string. It's not clear, though, in what format your server needs this base64 string. In what Content-Type is your server expecting the request to be? It would be very unusual for it to expect base64 string by itself. Commented Apr 15, 2015 at 2:05
  • If you really need to send a non-standard request, you wouldn't use POST, but rather you'd probably create your own AFHTTPRequestOperation object. But before we go down that road, it probably makes sense to confirm that your server is really expecting such a curious format for the POST request. Commented Apr 15, 2015 at 2:09
  • Solved the problem,thank you Very Much Commented Apr 15, 2015 at 5:47

1 Answer 1

1

Solve the problem

NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init]; [request setURL:[NSURL URLWithString:URLString]]; [request setHTTPMethod:@"POST"]; NSMutableData *postBody = [NSMutableData data]; [postBody appendData:[restrinBASE64STRING dataUsingEncoding:NSUTF8StringEncoding]]; [request setHTTPBody:postBody]; AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc]initWithRequest:request]; operation.responseSerializer = [AFHTTPResponseSerializer serializer]; [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) { } failure:^(AFHTTPRequestOperation *operation, NSError *error) { }]; [[NSOperationQueue mainQueue] addOperation:operation]; 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.