ios - 具有 204 响应且 Objective-C 中没有内容的 DELETE 请求的巨大延迟

标签 ios objective-c iphone api

我在使用 iOS 应用程序时遇到问题(我不是 iOS 开发人员,我负责该应用程序使用的 API)和 DELETE 请求。

Api 对 DELETE 请求使用没有内容的 204 响应,到目前为止,它对所有客户端应用程序都运行良好,没有任何问题。

问题是,当使用 NSUrlConnection 时,所有这些 DELETE 请求要么被处理超过 60 秒,要么由于超时而失败。

此行为仅在 iOS 实现中可见,其他客户端在不到 100 毫秒的时间内收到完全相同请求的响应。

这是常见的行为吗?有谁知道希望不需要重建 API 的任何修复方法?

创建下面的代码只是为了模拟此行为并在 API 开发团队端复制问题,但问题是相同的(当然,访问 token 被遮盖了,身份验证工作正常):

//
//  ViewController.m
//  NoteablesTest

#import "ViewController.h"

@interface ViewController ()
@property (weak, nonatomic) IBOutlet UILabel *loadingLabel;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    [_loadingLabel setHidden:true];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (IBAction)didButtonTouched:(id)sender {
    NSString *url = @"https://api.noteables.com/editing-session/c180af93-ad3a-4751-a96a-dc47ff7732d4";
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:url]];

    [request setHTTPMethod:@"DELETE"];

    [request setValue:@"Bearer XXXX" forHTTPHeaderField:@"Authorization"];

    [request setValue:@"Noteables/1.0 (iPhone; iOS 8.1.3; Scale/2.00)" forHTTPHeaderField:@"User-Agent"];

    [request setValue:@"application/vnd.api.v1+json" forHTTPHeaderField:@"Content-Type"];

    [request setValue:@"en;q=1" forHTTPHeaderField:@"Accept-Language"];

    NSDate *start = [NSDate date];

    [_loadingLabel setHidden:false];

    [NSURLConnection  sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {

        double timePassed = [start timeIntervalSinceNow];
        NSString *message = [NSString stringWithFormat:@"Elapsed: %f seconds", timePassed];
        [_loadingLabel setHidden:true];


        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Result!" message: message  delegate:self cancelButtonTitle:@"Am I satisfied with this?" otherButtonTitles:nil, nil];

        [alert show];

        NSLog(@"%@", response);
    }];


}

@end

最佳答案

尝试将您的 content-length header 设置为 0。

关于ios - 具有 204 响应且 Objective-C 中没有内容的 DELETE 请求的巨大延迟,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28684209/

相关文章:

ios - 观察异步请求

ios - 从 Parent ViewController 访问包含的 UIView 组件

iphone - 固定 UITableView 的高度

ios - iOS 7 中锁屏播放器的搜索栏问题

iphone - 如何在不复制 Xcode 4 项目的情况下从付费版本构建免费版本?

objective-c - 尝试捕捉不起作用

iphone - 我应该开始使用核心数据吗?

iphone - 如何正确更新Three20?

iphone - Passkit/存折iOS 5

objective-c - 为分段控件中的选定分段自定义颜色