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.
从 iOS 设备发送的任何 HTTP 请求返回204
状态和非空响应(由content-length
具有任何值 but的标头指示0
)将导致连接在设备上遇到超时。iOS 收到204
响应,然后丢弃内容,然后读取标头,然后错误地等待非空响应到达。
注意:iOS 模拟器不会遇到这个问题。这似乎是(真实的)仅限设备的问题。
由于无法检查 iOS 客户端的代码,有人认为这是 HTTP 请求端的无意处理错误,这意味着实现不符合标准。204 响应应忽略任何内容,因为它是“无内容”响应。