DELETE 请求的巨大延迟,响应为 204,Objective-C 中没有内容 [英] Huge delay on DELETE requests with 204 response and no content in Objective-C

查看:19
本文介绍了DELETE 请求的巨大延迟,响应为 204,Objective-C 中没有内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm having problem with iOS app (I'm not iOS developer, I'm responsible for API that that app uses) and DELETE requests.

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

Api is using 204 responses with no content for DELETE requests and that have worked fine for all the client applications so far, without any problems.

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

The issue is that when using NSUrlConnection all those DELETE requests either are processed for more than 60 seconds or fail because of timeout.

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

This behaviour is only visible in out iOS implementations, other clients are getting response for exactly same request in less than 100ms.

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

Is this common behaviour? Do anyone know any fix for that that hopefully doesn't require API rebuild?

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

Code below was created just to emulate this behaviour and replicate problem on API development team side, but problem is the same (Access token obscured of course, authentication works fine):

//
//  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 标头设置为 0.

Try setting your content-length header to 0.

这篇关于DELETE 请求的巨大延迟,响应为 204,Objective-C 中没有内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆