nsurlprotocol

NSURLSessionTask authentication challenge completionHandler and NSURLAuthenticationChallenge client

为君一笑 提交于 2019-12-04 09:34:13
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 disposition, NSURLCredential *credential))completionHandler; Here I am basically provided with two

Is there a way to use NSURLProtocol in a NSURLSession with custom config?

两盒软妹~` 提交于 2019-12-04 05:23:48
I have a NSURLSession that runs in a background queue. I'm adding my NSURLProtocol subclass to the NSURLsessionConfiguration.protocolClases but the override class func canInitWithRequest(request: NSURLRequest) -> Bool never gets called. This is how I'm adding my NSURLProtocol let configuration = NSURLSessionConfiguration.defaultSessionConfiguration() configuration.protocolClasses!.append(MockNetwork) urlSession = NSURLSession(configuration: configuration, delegate: self, delegateQueue: operationQueue) Also I tried with the session not running on background doing but also didn't work: let

NSURLProtocol canInitWithRequest: called multiple times

假如想象 提交于 2019-12-04 03:37:52
Our app has a lot of web views in it and I recently added a NSURLProtocol to interceptor some of the requests from them. I've noticed that some of the web views are calling the +[NSURLPRotocol canInitWithRequest:] method multiple times with what appears to be exactly the same request. Sometimes 6 or 7 times. I'm trying to figure out why this might be occurring. Does anyone have any experience with this? I've logged out the [NSURL absoluteString] and httpMethod values and they are the same for each request. I would expect that this method would only be called once for any given file or resource

Why is the HTTPBody of a request inside an NSURLProtocol Subclass always nil?

冷暖自知 提交于 2019-12-01 07:40:43
问题 I have my NSURLProtocol MyGreatProtocol . I add it to the URL Loading system, NSURLProtocol.registerClass(MyGreatProtocol) I then start receiving events inside MyGreatProtocol during network sessions. Suppose I create the session after registering my protocol, let session = NSURLSession.sharedSession() let request = NSMutableURLRequest(URL: NSURL(string:"http://example.com")!, cachePolicy: .ReloadIgnoringLocalCacheData, timeoutInterval: 2.0) //arbitrary 404 request.HTTPBody = ([1, 3, 3, 7] as

Using a custom NSURLProtocol with UIWebView and POST requests

两盒软妹~` 提交于 2019-11-30 19:01:15
In my iOS app, I'm using a UIWebView and a custom protocol (with my own NSURLProtocol implementation). I've been fairly careful about making sure that whenever I load a url, I load something like this into my UIWebView: myprotocol://myserver/mypath and in my NSURLProtocol implementation, I take a mutable copy of the NSURLRequest, convert the URL to http: and send that to my server. Everything works for HTTP GET requests. The problem I encounter is with POST requests. It seems like the UIWebView doesn't properly encode the form data in the HTTPBody if the request uses my custom protocol. One

NSURLProtocol isn't asked to load after YES response to canInitWithRequest

假装没事ソ 提交于 2019-11-28 13:01:30
I'm registering an implementation of NSURLProtocol to do some custom handling of certain URL requests (I tag these requests by setting properties on them). These URL requests are coming from a UIWebView's load method. Create a UI web view (first load after launch) Load content Destroy web view Create a new web view (subsequent loads) Load content I'm seeing significantly different behavior between steps 2 and 5. My NSURLProtocol implementation manages cached data and is designed to handle the requests. If I don't detect my property in a request, I do a second check for a specific URL (for

How to mock AJAX call with NSURLProtocol?

久未见 提交于 2019-11-28 06:58:40
I have UIWebview that makes AJAX calls to external services. When offline i need to catch theses requests and return local json. I implemented a NSURLProtocol and i manage to catch the AJAX request, the problem is jquery always return a 0 error code : $.ajax({ url: url, dataType: 'json', contentType: "application/json", success: function(jsonData){ alert("success :"); }, error: function (request, status, error) { alert("failure :" + request.status ); } }); I always get a request.status = 0 To test my protocol I tried to mock an image inside my html and it works great. HTML request to an image

How to play movie with a URL using a custom NSURLProtocol?

雨燕双飞 提交于 2019-11-28 05:08:42
As you know,play a movie with MPMoviePlayerController object using [[MPMoviePlayerController alloc] initWithContentURL: aURL]; now ,i want to achieve a custom NSURLProtocol in which i will decrypt a movie source that had be encrypt by AlgorithmDES. Is that possibility? thanks for giving any ideas.need you help~ UPDATE: I spoke to Apple about this and it's not possible to use MPMoviePlayerController with a NSURLProtocol subclass at the moment! Hej, I am not sure but it could be possible. I am currently working on something similar but haven't got it fully working. What I have found out is that

NSURLConnection delegate methods are not called

元气小坏坏 提交于 2019-11-27 18:05:42
I am trying to create a simple NSURLConnection to communicate with a server using a GET request. Connection works well, but delegates methods of NSURLConnection are never called.. Here is what am doing: NSString *post = [NSString stringWithFormat:@"key1=%@&key2=%@&key3=%f&key4=%@", val1, val4, val3, val4]; NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease] ; [request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://www.domain.com/demo/name/file.php?%@", post]]]; NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate

NSURLProtocol isn't asked to load after YES response to canInitWithRequest

馋奶兔 提交于 2019-11-27 07:33:22
问题 I'm registering an implementation of NSURLProtocol to do some custom handling of certain URL requests (I tag these requests by setting properties on them). These URL requests are coming from a UIWebView's load method. Create a UI web view (first load after launch) Load content Destroy web view Create a new web view (subsequent loads) Load content I'm seeing significantly different behavior between steps 2 and 5. My NSURLProtocol implementation manages cached data and is designed to handle the