nsurlrequest

Cocoa File Upload with Progress Bar

前提是你 提交于 2019-12-06 04:30:14
(This is really a double-whammy in terms of questions, since there really is two serperate questions, but they kinda belong together.) First Question: How would I go about uploading a file (I have an NSData object containing the file's contents already) using POST, while displaying the upload progress in an NSProgressIndicator ? Much like one can do bytesReceived in NSURLDownload , but this time tracking how many bytes have already been sent using POST. Second Question: While I have this NSData Array, I shall be using the code below to send the NSData array. Here, it confuses me how I would

Multiple async webservice requests NSURLConnection iOS

吃可爱长大的小学妹 提交于 2019-12-06 02:44:29
问题 I have a problem that Im not sure how to tackle. I can without any problem make requests to the REST service when passing a single request. My problem now is at based on that respons i get some values including ID´s. All ID´s retrieved will then need make another request to collect new information. My guess is to load all the specific request in a array or dictionary and create request from that. Anyone have some useful tips regarding this? The information retrieved will then populate a

iOS store-and-forward framework for offline HTTP POST requests

倾然丶 夕夏残阳落幕 提交于 2019-12-06 01:52:34
Is there a way (presumably a library?) to store HTTP POST requests when the user is offline, and then transmit the POST requests when the user is back online? (I don't need to read the server's response, except insofar as I'll want to re-queue the requests if the POST request fails.) Yes, there is such a library: http://blog.mugunthkumar.com/products/ios-framework-introducing-mknetworkkit/ It is resilient against quits and relaunch of your app, and will keep trying to send your request until there is persistent failure (such as server down, not network down) Is there a way (presumably a

NSUrlRequest from curl for stripe

≡放荡痞女 提交于 2019-12-05 21:30:17
I need to make a http post request using the following instructions: curl https://api.stripe.com/v1/tokens \ -u sk_test_BQokikJOvBiI2HlWgH4olfQ2: \ -d "bank_account[country]=US" \ -d "bank_account[routing_number]=110000000" \ -d "bank_account[account_number]=000123456789" I have no idea how to go from curl to NSUrlrequest, especially the -u (user?) part. The stripe SDK has left this out from their SDK and has no example on their site. Thanks EDIT:I created another answer specifically for getting a token for a bank_account. This answer was for generally how to make a call using parse's back end

NSURLRequest cache issue iOS 7

醉酒当歌 提交于 2019-12-05 16:59:28
in iOS 7 cachePolicy doesn't work, it just cache the downloaded json. //URLRequest NSString *url = [NSString stringWithFormat:@"http://www.semhora.com/jsonparser/categories/categories_%d_test.json", _categoriesIndex]; NSURLRequest *theRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:url] cachePolicy:NSURLCacheStorageNotAllowed timeoutInterval:60.0]; How can I disallow cache in iOS 7? I encountered the same problem and I verified that setting cachePolicy = 0 instead of cachePolicy = NSURLCacheStorageNotAllowed fixes the problem. This doesn't make sense to me either since 0 corresponds

NSDate to RFC 2822 Date format

懵懂的女人 提交于 2019-12-05 16:54:29
Is there any efficient way to convert an NSDate to RFC 2822 Date format string ? I want to use this string to create an NSURLRequest and set the value of "If-Modified-Since" header field. try to use an NSDateFormatter NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; // maybe there exist a new-method now dateFormatter.dateFormat = @"EEE, dd MMM yyyy HH:mm:ss Z"; //RFC2822-Format NSString *dateString = [dateFormatter stringFromDate:myDate]; Swift 3 let rfcDateFormat = DateFormatter() rfcDateFormat.dateFormat = "EEE, dd MMM yyyy HH:mm:ss Z" let dateSTring = rfcDateFormat.string

NSURLSession delegate methods not called

浪尽此生 提交于 2019-12-05 13:23:51
I have created a very simple app to download a text file from my web server. I have this working perfectly with NSURLConnection, but am trying to migrate over to NSURLSession instead. The issue I am having is that none of the delegate methods are being called. My server is password protected so I need to use the basic http authentication to access the file, but when the didReceiveChallenge method is never called. The line of code [getFileTask resume] seems to have no effect on anything. My setup is as follows: @interface ViewController : UIViewController <NSURLSessionDelegate,

HTTPS POST from iPhone using NSURLConnection hangs for certain filesize range

情到浓时终转凉″ 提交于 2019-12-05 11:40:55
I'm using NSURLConnection to make an async HTTPS POST to our webservice to upload a jpg. It works fine most of the time. But when the post body is between 196609 and 196868 bytes (inclusive), the connection hangs after the file has been uploaded 100% (didSendBodyData tells me that it's 100% sent). Then after 5 minutes, the connection times out with the message "The network connection was lost." Larger and smaller filesizes work. I've tested this by capping the filesize of the file that I add to the post body. The content length is getting set correctly. See the code below. The upload looks

NSURLSessionConfiguration HTTPAdditionalHeaders not set

拜拜、爱过 提交于 2019-12-05 06:04:43
Authorization header is set in NSURLSessionConfiguration , however it is not attached to NSURLSessionDataTask . Is this a bug in Foundation framework ? NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration]; [configuration setHTTPAdditionalHeaders:@{@"Authorization":@"123"}]; // Initialize session with NSURLSessionConfiguration NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration]; NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url]; NSURLSessionDataTask *sessionTask = [session dataTaskWithRequest

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

有些话、适合烂在心里 提交于 2019-12-05 03:27:30
问题 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,