Ios 使用afp网络的PUT方法
我想用put请求实现afnetworking,但运行它时总是显示错误。 使用post方法可以很好地工作,但当我将其更改为PUT时,它会显示错误Ios 使用afp网络的PUT方法,ios,networking,afnetworking,nsurlrequest,put,Ios,Networking,Afnetworking,Nsurlrequest,Put,我想用put请求实现afnetworking,但运行它时总是显示错误。 使用post方法可以很好地工作,但当我将其更改为PUT时,它会显示错误 AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:urls]; [httpClient defaultValueForHeader:@"Accept"]; NSDictionary *params = [NSDictionary dictionaryWith
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];
错误显示:
Error Domain=AFNetworkingErrorDomain Code=-1011“预期状态代码在(200-299)中,获得404”UserInfo=0x75a9d40{nsLocalizedRecoverysSuggestion={“状态”:false,“错误”:“未知方法”。}不确定您是否意识到这一点,但该错误意味着找不到您试图在服务器上访问的资源(404 HTTP状态代码)。因此,您指定的路径(实际上没有)根本不可用,或者不只是响应PUT请求。您确定要访问的Web服务的根路径无效吗?请确保您的
AFHTTPClient
的URL格式正确。如AFHTTPClient.h
()