1

我正在尝试将 ASIFormDataRequest 与 setPostValues 和方法 DELETE 一起使用,以下是代码行

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];

在成功方法中,我得到代码 405 NSLog(@"%d",[request responseStatusCode]);

当我从邮递员客户那里打到它时,它就起作用了。请让我知道我在哪里做错了。

4

1 回答 1

1

当您使用带有一些 post 参数的 DELETE 方法时,您需要在设置 Http DELETE 方法之前调用“buildPostBody”函数,如下所示

[notificationAPNRequest setPostValue:deviceId forKey:@"deviceId"]; [通知APNRequest setPostValue:apnToken forKey:@"apnToken"];

[通知APNRequest buildPostBody]; /// 在设置请求方法之前调用这个

[notificationAPNRequest setRequestMethod:@"DELETE"];

希望它现在有效

于 2013-03-20T11:52:21.857 回答