本文介绍了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.

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

10-29 20:53