简体   繁体   中英

How to use PUT Method in RestKit 0.20.2 in iphone

Already i used the POST with Restkit is working fine. But i don't know what is difference between POST and PUT in Restkit. I just changed the method type only to "PUT". But my parameter is not sending to Webservice.

Below is my code, the same code for POST is working to me.

AFHTTPClient *client = [AFHTTPClient clientWithBaseURL:URL];
[client setDefaultHeader:@"Authorization" value:[DSUserDefaults user].accessToken];

NSDictionary *prefDict=[NSDictionary dictionaryWithObjectsAndKeys: @"",@"COMPANY_ID" ,@"",@"JOBTITLE",@"2",@"JOBTYPE" ,@"San Franscisco, US",@"LOCATION", nil];
NSLog(@"prefDict  %@",prefDict);

NSMutableURLRequest *request = [client requestWithMethod:PUT path:@"" parameters:prefDict];
[request setURL:URL];
[request setTimeoutInterval:60.0];
[request setHTTPMethod:PUT];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
[AFHTTPRequestOperation addAcceptableStatusCodes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(100, 500)]];

[operation setCompletionBlockWithSuccess: ^(AFHTTPRequestOperation *operation, id responseObject) {
    NSLog(@"operation.responseString: %@", operation.responseString);

    NSData *data =[operation.responseString dataUsingEncoding:NSUTF8StringEncoding];
   }

How to send "text" data to request. I don't need to send as dictionary.

PUT and POST aren't different settings in RestKit, they are different HTTP upload type settings which are passed into the URL request that will be sent. As such, they are handled by the server. If the server isn't configured to handle them then you will not get the expected functionality. GET and POST are relatively common, PUT is less common so may not be covered in your server implementation.

See here for details on POST, PUT and GET.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM