【发布时间】:2016-09-19 23:39:47
【问题描述】:
我已经实现了一个使用iOS9的NSURLSession进行http2通信的程序,它可以在http2中与我的服务器通信。 但是,我在接收server_push 时遇到问题。 我发现他们的设置中的 ENABLE_PUSH 值为 0,并且在 NSURLSession 中接收服务器推送中没有委托...
·我认为 NSURLSession 不支持 server_push。是这样吗?
・如果支持server_push,如何使用?
/**
It WORKS for post data and get response.
I don't know the code should be added here
in order to get the server_push.
I suspect that NSURLSession itself cannot receive the server_push(;_;)
**/
- (void) postData
{
NSString *urlstr = self.urlArea.text;
NSURL * url = [NSURL URLWithString:urlstr];
NSDictionary *params = @{@"data":@""};
//json to query
NSData *query = [self buildQueryWithDictionary: params];
//make request
NSMutableURLRequest *request = [NSMutableURLRequest
requestWithURL:url
cachePolicy: NSURLRequestReloadIgnoringCacheData
timeoutInterval: 10.0];
[request setHTTPMethod: @"POST"];
[request setHTTPBody: query];
//prepare session
NSURLSession *session = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration] delegate:self delegateQueue:[NSOperationQueue mainQueue]];
//resume
[[session dataTaskWithRequest: request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error)
{
if (response && ! error) {
NSLog(@"Data: %@", [[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding]);
}else {
NSLog(@"ERR: %@", error);
}
}] resume];
}
【问题讨论】:
-
嗨 T_ms,欢迎来到 SO。您应该发布您的代码,并详细说明您遇到了什么样的接收问题。
-
嗨,J.Chomel,感谢您的建议:-) 我发布了!
标签: ios objective-c nsurlsession http2