nsurlsessiondatatask

iOS UrlSession.shared.dataTask removes utf-8 “+” character and replaces it with “ ”

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-12 21:16:34
问题 I'm creating a login call to an API using x-www-form-endoded data. I created a POST in Postman and received a 200 response. I used Postman's export function to generate the OKHTTP code for Android and NSURL code for iOS. The Android code works fine, but the iOS code receives a 401 response. I used Charles web debugging proxy to look at what was actually being sent for the payload. For android the username is correctly represented as "username=james+jypsee@jypsee.com" but in iOS it comes out

0 bytes of data from HTTPS URLSession.dataTask

假装没事ソ 提交于 2019-12-11 06:29:49
问题 I'm trying to retrieve some JSON data from a URL, however it is returning 0 bytes every time in the data. I've checked several different SO posts, and none seem to match the exact problem I am having as the server I am getting data from indeed uses HTTPS with TLS 1.2. So I don't think there's anything I need to add to my info.plist, though I could be wrong. Here is my code: var tournaments: [Tournament] = [] /// Base API URL let baseURL: String = "https://www.burningmeter.com/tournaments.json

NSURLSessionTask. Suspend does not work

自古美人都是妖i 提交于 2019-12-10 13:29:17
问题 This is what Apple's documentation says regarding suspend method of NSURLSessionTask class A task, while suspended, produces no network traffic and is not subject to timeouts. Ok. So I'm running the following simple code: let url = NSURL(string: "http://httpbin.org/delay/10")! let urlRequest = NSURLRequest(URL: url) self.task = NSURLSession.sharedSession().dataTaskWithURL(urlRequest.URL!, completionHandler: { data, response, error in print("completion ERROR \(error)") }) self.task.resume()

Using NSURLSession inside NSURLProtocol

元气小坏坏 提交于 2019-12-10 12:23:23
问题 I'm trying to create a transparent NSURLProtocol for http:// and https:// connections using NSURLSession. However at the moment, even though the completion handler is being run, URL requests with the app (UIWebView) are coming back blank. Does anybody have any ideas? Code is below: #import "MyURLProtocol.h" // AppDelegate #import "AppDelegate.h" static NSString * const MyURLProtocolHandledKey = @"MyURLProtocolHandledKey"; @interface MyURLProtocol () <NSURLConnectionDelegate

Moving from NSURLConnection to NSURLSession for SOAP POST in Swift

橙三吉。 提交于 2019-12-08 05:48:25
问题 I am trying to move over from NSURLConnection over to NSURLSession for a SOAP post, but seem to have issues with the NSURLSessionDataDelegate. Here is the old code in NSURLConnection that works fine: let soapMessage = "<?xml version='1.0' encoding='UTF-8'?><SOAP-ENV:Envelope xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/' xmlns:ns1='http://tempuri.org/'><SOAP-ENV:Body><ns1:get_Countries/></SOAP-ENV:Body></SOAP-ENV:Envelope>" print("Soap Packet is \(soapMessage)") let urlString =

Moving from NSURLConnection to NSURLSession for SOAP POST in Swift

佐手、 提交于 2019-12-06 16:38:49
I am trying to move over from NSURLConnection over to NSURLSession for a SOAP post, but seem to have issues with the NSURLSessionDataDelegate. Here is the old code in NSURLConnection that works fine: let soapMessage = "<?xml version='1.0' encoding='UTF-8'?><SOAP-ENV:Envelope xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/' xmlns:ns1='http://tempuri.org/'><SOAP-ENV:Body><ns1:get_Countries/></SOAP-ENV:Body></SOAP-ENV:Envelope>" print("Soap Packet is \(soapMessage)") let urlString = "https://example.com/Service.svc" let url = NSURL(string: urlString) let theRequest = NSMutableURLRequest

NSURLSessionTask authentication challenge completionHandler and NSURLAuthenticationChallenge client

感情迁移 提交于 2019-12-06 06:08:48
问题 I am implementing a custom NSURLProtocol , and internally want to use NSURLSession with data tasks for internal networking instead of NSURLConnection . I have hit an interesting problem and wonder about the internal implementation of the challenge handler of NSURLSession / NSURLSessionTask . - (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition

How to sync serial queue for URLSession tasks?

ⅰ亾dé卋堺 提交于 2019-12-06 03:42:54
问题 Using XCode-8.2.1, Swift-3.0.2 and iOS-10.2.1, I am trying to call two different URLSession.shared.dataTasks (the first is a simple URL-request and the second is a POST-request). Since my first dataTask delivers a result that is needed in the httpBody of the second dataTask, the two URLSession.shared.dataTasks shall run in series, one after the other! (and also the preparative code shall run consecutively). I tried, so far, using two consecutive serialQueue.sync{} queues. But I had to realize

NSURLSession HTTP/2 memory leak

試著忘記壹切 提交于 2019-12-05 17:15:24
问题 This My Test cases, point out that when using NSURLSession with a HTTP/2 connection there is memory problem. test1: iOS 9. HTTP/2 server I use NSURLSession to upload 10M file to a HTTP/2 server, if the file uploaded completed everything is ok, But if I cancel the upload task before it's completed, the 10M will never release. test2: iOS 9. HTTPs1.1 server I test the same code with a https1.1 file server, I cancel the upload task or not, everything is ok, the memory back to normal.(10M data is

iOS background task using NSURLSessionDataTask

柔情痞子 提交于 2019-12-04 20:17:58
I have flight search feature in my application which is taking too long to get the data (more than 25 seconds). if application goes background or went to sleep mode, internet connection get disconnected. I have written below logic using apple example to make api request keep going even though if app goes to background but it's not working. self.session = [self backgroundSession]; self.mutableData = [NSMutableData data]; NSURL *downloadURL = [NSURL URLWithString:@"http://jsonplaceholder.typicode.com/photos"]; NSURLRequest *request = [NSURLRequest requestWithURL:downloadURL]; self.dataTask =