0

I am trying to send a http url request of method type 'PATCH' below is my sample code .

NSString *urlString=@"http://0.0.0.0:8000/v1/APvk";
para=[para stringByAppendingFormat:@"/%@?accessToken=",@"SOMEID"];
para= [para stringByAppendingString:@"SOMEACCESSTOKEN"];

NSURL *url = [NSURL URLWithString:para];


NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
if (!request) NSLog(@"Error creating the URL Request");

[request setHTTPMethod:@"PATCH"];
[request setHTTPBody:data];
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];

// Send a synchronous request
NSURLResponse * response = nil;
NSError * NSURLRequestError = nil;
NSData * responseData = [NSURLConnection sendSynchronousRequest:request
                                              returningResponse:&response
                                                          error:&NSURLRequestError];

NSLog(@"%@",responseData);
NSDictionary *Replyfromserver=[NSJSONSerialization JSONObjectWithData:responseData options:0 error:nil];
NSLog(@"%@",Replyfromserver);

I don't know how to send a PATCH request I am just doing the same way we send a POST request ,here I am getting a message from server that is "Invalid Payload" Help me out of this.

  • 1. It will be better for you to use NSURLSession instead of NSURLConnection , refer to here :https://stackoverflow.com/questions/34902494/send-http-patch-request-in-ios-objective-c , 2. make sure the web service supports PATCH request. – ColeX Aug 04 '17 at 05:28
  • The web service supports PATCH request but i did'nt tried with NSURLSession – Bhaskar Uday Aug 04 '17 at 05:33

0 Answers0