我想用put请求实现afnetworking,但是当我运行它时它总是显示错误。 使用post方法可以正常工作,但是当我将其更改为PUT时,它会显示错误。
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:urls];
[httpClient defaultValueForHeader:@"Accept"];
NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:
@"345", @"page_id",
@"john",@"username",
nil];
NSMutableURLRequest *request = [httpClient requestWithMethod:@"PUT"
path:@""
parameters:params];
//Add your request object to an AFHTTPRequestOperation
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc]
initWithRequest:request];
[httpClient registerHTTPOperationClass:[AFHTTPRequestOperation class]];
[operation setCompletionBlockWithSuccess:
^(AFHTTPRequestOperation *operation,
id responseObject) {
NSString *response = [operation responseString];
NSLog(@"response: [%@]",response);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"error: %@", [operation error]);
}];
//call start on your request operation
[operation start];
错误说:
错误域= AFNetworkingErrorDomain代码= -1011“(200-299)中的预期状态代码,得到404”UserInfo = 0x75a9d40 {NSLocalizedRecoverySuggestion = {“status”:false,“error”:“Unknown method。”}