DELETE请求的延迟很大,有204个响应,Objective-C中没有内容

Ada*_*dam 5 iphone api objective-c ios

我有iOS应用程序的问题(我不是iOS开发人员,我负责该应用程序使用的API)和DELETE请求.

Api使用了204个响应,没有DELETE请求的内容,到目前为止,所有客户端应用程序都运行正常,没有任何问题.

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

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

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

创建以下代码只是为了模拟这种行为并在API开发团队方面复制问题,但问题是相同的(当然,访问令牌模糊,身份验证工作正常):

//
//  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
Run Code Online (Sandbox Code Playgroud)

Aar*_*ger 11

尝试将content-length标题设置为0.

  • 你可以删除这个你想要的感谢评论 - 如果只有Aaron在删除之前就能看到它:Aaron,我这么努力,我希望我能给你1千名代表.我有一个web api注入的c#应用程序返回204并带有一点注释 - 这个注释改变了内容长度到注释的长度(+2个字符(wtf?)),这使得Safari @ iOS和只有这个客户端产生这个奇怪的超时.谢谢.事实上:太谢天谢地,如果我见到你,我会当场给你买一瓶我个人最喜欢的巨型微型IPA啤酒.我会为你的敬意干杯. (3认同)

arv*_*ahl 6

从 iOS 设备发送的任何 HTTP 请求返回204状态和非空响应(由content-length具有任何值 but的标头指示0)将导致连接在设备上遇到超时。iOS 收到204响应,然后丢弃内容,然后读取标头,然后错误地等待非空响应到达。

注意:iOS 模拟器不会遇到这个问题。这似乎是(真实的)仅限设备的问题。

由于无法检查 iOS 客户端的代码,有人认为这是 HTTP 请求端的无意处理错误,这意味着实现不符合标准。204 响应应忽略任何内容,因为它是“无内容”响应。