IOS sending post method data can access in php as get method

别说谁变了你拦得住时间么 提交于 2019-12-02 10:51:27

Please Download this file https://www.dropbox.com/s/tggf5rru7l3n53m/AFNetworking.zip?dl=0

And import file in your project Define in #import "AFHTTPRequestOperationManager.h"

AFHTTPRequestOperationManager *manager = [[AFHTTPRequestOperationManager alloc] initWithBaseURL:[NSURL URLWithString:@"Your Url"]];
   NSDictionary *parameters = @{@"emp_id":SaveID2,@"job_code":txtJobcode1.text,@"status":alertTextField.text};

   AFHTTPRequestOperation *op = [manager POST:@"rest.of.url" parameters:parameters constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {

   } success:^(AFHTTPRequestOperation *operation, id responseObject) {


      NSLog(@"Success: %@ ***** %@", operation.responseString, responseObject);
      manager.responseSerializer = [AFHTTPResponseSerializer serializer];
      [responseObject valueForKey: @"data"];



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

      NSLog(@"Error: %@ ***** %@", operation.responseString, error);
   }];
   [op start]; 

because you send your data via query string in url
i think it will work if you try to pass data in your request's body:[urlRequest setHTTPBody:...]

POST parameters come from the request body, not from the URL string. You'll need to:

  • Call setHTTPBody on the request and provide the URL-encoded string (sans question mark, IIRC) as the body data
  • Call setValue:forHTTPHeaderField: to set the Content-Type to application/x-www-form-urlencoded
  • Either remove the call to [connection start] or use initWithRequest:delegate:startImmediately: so that you aren't starting the connection twice.

That last one is kind of important. You can get strange results if you try to start a connection twice. :-)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!