nsurlrequest

Swift 3: URLSession / URLRequest Not Working

瘦欲@ 提交于 2019-12-04 03:04:15
问题 I am still trying to convert our application from Swift 2 over to Swift 3 because I am being forced to since all of our Apple devices are now running iOS 10. I have gone through the code conversion and thought I was doing well however, while attempting to debug my JSON issues (posted in another question), I am now dealing with requests not even being sent. let params: [String:AnyObject] = [ "email":"\(self.preferences.string(forKey: "preference_email")!)" as AnyObject ] let requestParams:

NSURLSession delegation: How to implement my custom SessionDelegate class accordingly?

霸气de小男生 提交于 2019-12-03 20:45:06
Got a singleton class, so called RequestManager, which shall handle requests made by different modules and background tasks of my application. @interface RequestFactory : NSObject - (void)requestDataWith:(NSString *)token id:(NSString *)id sender:(id<RequestFactoryDelegate>)sender; ... @end Then I got another class, so called SessionDelegate, which shall handle all the callbacks during the request. @interface SessionDelegate : NSObject <NSURLSessionDelegate, NSURLSessionTaskDelegate, NSURLSessionDataDelegate> @property (weak, nonatomic) id <RequestFactoryDelegate> delegate; @end My idea is to

Handling a NSURLRequest with timeout when using delegate

别来无恙 提交于 2019-12-03 12:57:49
I'm using a NSMutableURLRequest to connect to a web site to get a JSON response. I'm doing so by generating the request, and then using NSURLConnection with a delegate of self to handle the async connection. I've implemented all the normal delegate methods: - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error - (void)connectionDidFinishLoading:(NSURLConnection *)connection All works perfectly with getting data back, dealing with any errors that occur, etc. However with the timeout on

Swift 2.0, Alamofire: Set cookies in HTTP Post Request

冷暖自知 提交于 2019-12-03 12:27:08
I want to set cookies in my HTTP POST request. Something like the cookie field in the HTTP Request below, version: 0.1.7 Cookie: client=Android; version=0.1.7; sellerId=SEL5483318784; key=178a0506-0639-4659-9495-67e5dffa42de Content-Type: application/x-www-form-urlencoded; charset=UTF-8 Content-Length: 1431 How can I achieve this with Alamofire? My current Alamofire request is like this, Alamofire.request(.POST, ServerConfig.ADD_PRODUCT_URL, parameters: productJSON, encoding: .JSON, headers: nil) .responseJSON(completionHandler: { responseRequest, responseResponse, responseResult in print

Constantly growing memory allocation while fetching images over HTTP in iOS

你离开我真会死。 提交于 2019-12-03 09:04:53
问题 I am implementing an iOS App that needs to fetch a huge amount of images over HTTP. I've tried several approaches but independently what I do, Instuments shows constantly increasing memory allocations and the App crashes sooner or later when I run it on a device. There are no leaks shown by Instruments. So far I have tried the following approches: Fetch the images using a synchronous NSURLConnection within an NSOperation Fetch the images using a asynchronous NSURLConnection within an

Resume download functionality in NSURLConnection

孤街醉人 提交于 2019-12-03 08:26:41
问题 I am downloading some very large data from a server with the NSURLConnection class. How can I implement a pause facility so that I can resume downloading? 回答1: You can't pause, per-se, but you can cancel a connection, and then create a new one to resume where the old left off. However, the server you're connecting to must support the Range header. Set this to "bytes=size_already_downloaded-", and it should pick up right where you cancelled it. 回答2: To resume downloading and get the rest of

ZIP file content type for HTTP request [duplicate]

岁酱吖の 提交于 2019-12-03 08:06:13
问题 This question already has answers here : .rar, .zip files MIME Type (5 answers) Closed 6 years ago . I am sending a zip file to server via HTTPREQUEST. What should be the Content-Type HTTP header value for this kind of file? The file is a ZIP archive that contains images on type PNG. Thanks 回答1: .zip application/zip, application/octet-stream 回答2: The standard MIME type for ZIP files is application/zip . The types for the files inside the ZIP does not matter for the MIME type. As always, it

How to query the last modification date of a file via HTTP on the iPhone using NSHTTPURLResponse?

我只是一个虾纸丫 提交于 2019-12-03 07:32:39
In my iPhone application I need to query the last modification date of an internet .m4a file via HTTP , but I DON'T want to downloading it. I'm reading Apple's documentation about NSURLRequest and NSHTTPURLResponse , but it seems to be all related to downloading the file and not querying it first. Maybe I'm wrong. How can I know the last modification date of a .m4a file, via HTTP , WITHOUT downloading it? Thanks! This answer assumes your server supports it, but what you do is send a "HEAD" request to the file URL and you get back just the file headers. You can then inspect the header called

Can you intercept NSURLRequests in a UIWebView without breaking the back button?

烂漫一生 提交于 2019-12-03 07:22:36
问题 I'm having trouble loading custom HTML into my UIWebView without breaking its goBack method. What Works I'm intercepting the URL requests of my UIWebView so I can load custom HTML. I have control over all the HTML, so I have my special app requests use a custom scheme (ie. myapp://arg1/?arg2=val ) that I can parse in webView:shouldStartLoadWithRequest:navigationType: . I decide what HTML I really want to load and call loadHTMLString:baseURL and return NO to cancel the original request. What

How to add custom header to AFNetworking on a JSONRequestOperation

╄→尐↘猪︶ㄣ 提交于 2019-12-03 05:48:52
问题 Hi, I have the following code accessing a URL: NSString * stringURL = [NSString stringWithFormat:@"%@/%@/someAPI", kSERVICE_URL, kSERVICE_VERSION]; NSURLRequest * request = [NSURLRequest requestWithURL:[NSURL URLWithString:stringURL]]; AFJSONRequestOperation * operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) { completionHandler(JSON, nil); } failure:^(NSURLRequest *request, NSHTTPURLResponse