我正在尝试使用带有setPostValues和方法DELETE的ASIFormDataRequest,以下是代码行
NSString *urlstring = [NSString stringWithFormat:@"%@%@",notificationsURL, typeId];
NSLog(@"Notification URL == %@",urlstring);
NSURL *urlR = [NSURL URLWithString:urlstring];
notificationAPNRequest = [ASIFormDataRequest requestWithURL:urlR];
notificationAPNRequest.timeOutSeconds = 30;
notificationAPNRequest.useSessionPersistence = NO;
[notificationAPNRequest setPostValue:deviceId forKey:@"deviceId"];
[notificationAPNRequest setPostValue:apnToken forKey:@"apnToken"];
if ([methodStr isEqualToString:@"OFF"]) {
[notificationAPNRequest setRequestMethod:@"DELETE"];
}
else if ([methodStr isEqualToString:@"ON"]) {
[notificationAPNRequest setRequestMethod:@"PUT"];
}
[notificationAPNRequest setDelegate:self];
[notificationAPNRequest setDidFinishSelector:@selector(notificationAPNSuccess:)];
[notificationAPNRequest setDidFailSelector:@selector(notificationAPNFailure:)];
[notificationAPNRequest startAsynchronous];
在Success方法中,我得到了Code 405
NSLog(@"%d",[request responseStatusCode]);
当我从邮差客户端点击时,它的工作原理。请让我知道我错误的地方。
答案 0 :(得分:1)
当你使用带有一些post参数的DELETE方法时,你需要在设置Http DELETE方法之前调用“buildPostBody”函数,如下所示
[notificationAPNRequest setPostValue:deviceId forKey:@“deviceId”]; [notificationAPNRequest setPostValue:apnToken forKey:@“apnToken”];
[notificationAPNRequest buildPostBody]; ///在设置请求方法之前调用它
[notificationAPNRequest setRequestMethod:@“DELETE”];
希望现在有效