我在使用 iOS 应用程序(我不是 iOS 开发人员,我负责该应用程序使用的 API)和删除请求时遇到问题。
Api 使用没有 DELETE 请求内容的 204 响应,到目前为止,该响应对于所有客户端应用程序都运行良好,没有任何问题。
问题是,使用 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
尝试设置您的content-length
标头为 0。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)