我已經實現了一個使用iOS9的NSURLSession來傳遞http2的程序,並且它可以在http2中與我的服務器進行通信。 但是,收到server_push時遇到問題。 我發現他們的設置ENABLE_PUSH值爲0,並且在NSURLSession中沒有接收服務器推送中的委託...Http/2 server_push with 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,你的建議thanx :-)我張貼! –