nsurlrequest

Add HTTP Header to NSURLRequest

牧云@^-^@ 提交于 2019-11-27 11:18:28
Is there any way to add HTTP header to NSURLRequest object? I used to add them in NSMutableURLRequest using: [request addValue:@"PC" forHTTPHeaderField:@"machineName"] I don't think you can modify the HTTP Headers of a NSURLRequest . I think you're trying to modify a NSURLRequest object that you didn't initialize? You could create a mutableCopy of your request and then set the header fields with the following method: -(void)setValue:(NSString *)value forHTTPHeaderField:(NSString *)field. After that you can copy the mutable request back onto your NSURLRequest variable. EDIT : Added example

Using AFNetworking and HTTP Basic Authentication

醉酒当歌 提交于 2019-11-27 10:32:24
The following code successfully connects to my Ruby on Rails API and returns JSON using AFNetworking. What do I need to do to edit this to pass in a username and password so my API can use HTTP Basic Authentication? I've read their documentation, but I am new to both Objective-C and AFNetworking and it isn't currently making sense. NSURL *url = [[NSURL alloc] initWithString:@"http://localhost:3000/tasks.json"]; NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url]; AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^

Bad URL when requesting with NSURL

此生再无相见时 提交于 2019-11-27 09:07:09
I'm trying to request this kind of URL in iPhone 4.0 SDK (access token slightly modified because you don't really need to see it): https://graph.facebook.com/me?sdk=ios&sdk_version=2&access_token=123902817987|8cb9e8408d2685cef853cd80.9-747882379|UGu5NvcAHiXuGEGzkq&format=json&limit=40&until=1286619821 But I got this message: Failed with error: Error Domain=NSURLErrorDomain Code=-1000 "bad URL" UserInfo=0x9e657a0 {NSUnderlyingError=0x9e656a0 "bad URL", NSLocalizedDescription=bad URL} When I copied and pasted in Safari or Chrome, it works. I tried replacing | with %| as suggested here but doesn

Use a self-signed ssl certificate in an iphone app

痞子三分冷 提交于 2019-11-27 09:06:27
问题 I apologize in advance for the long-winded question. I'm having trouble with a self-signed SSL cert and I want to document everything I've tried so far. I'm working on an app that communicates with a REST service. The test server uses a self-signed ssl certificate that I can install on my computer without issue. It's a .p12 file that requires a password to install. Without this certificate installed, all requests to the server return a 403. The .p12 installs three items in the Keychain, a

UIWebView webpage caching for offline viewing

岁酱吖の 提交于 2019-11-27 07:07:40
First of all, I'm pretty sure that I have checked every answer here and nothing does what I would like to do. In this question, for answer is given ASIHTTPRequest which is dead project. ( How do I download an entire webpage (with images) on the iPhone? ) In this question, user proposed RNCachingURLProtocol which is really great but I had a few problems after closing app completely (closing it in task-bar). After that I didn't get css or images, only html was loaded. ( Cache a single webpage for use when offline in Xcode / UIWEBVIEW ). There are few more answers but none is good. There must be

How to make POST NSURLRequest with 2 parameters?

倾然丶 夕夏残阳落幕 提交于 2019-11-27 04:33:45
I want to add 2 parameters to NSURLRequest . Is there a way or should I use AFnetworking? It will probably be easier to do if you use AFNetworking. If you have some desire to do it yourself, you can use NSURLSession , but you have to write more code. If you use AFNetworking, it takes care of all of this gory details of serializing the request, differentiating between success and errors, etc.: NSDictionary *params = @{@"firstname": @"John", @"lastname": @"Doe"}; AFHTTPSessionManager *manager = [AFHTTPSessionManager manager]; [manager POST:urlString parameters:params success:^

NSURLRequest : Post data and read the posted page

僤鯓⒐⒋嵵緔 提交于 2019-11-27 03:12:33
In iOS (current target 5.0, Base SDK 5.1) how can I send a post request to a server, and then read the contents of the page. For example, the page takes a username and password, and then echos true or false. This is just for a better understanding of NSURLRequest. Thanks in Advance! A few things first Decide how you want to encode your data - JSON or url-encoding are a good start. Decide upon a return value - will it be 1, TRUE or 0, FALSE, or even YES/non-nil nothing/nil. Read up on the URL Loading System , it's your friend. Aim to make all your url connections asynchronous so your UI remains

NSMutableURLRequest not obeying my timeoutInterval

假装没事ソ 提交于 2019-11-27 03:03:48
I'm POST'ing a small image, so i'd like the timeout interval to be short. If the image doesn't send in a few seconds, it's probably never going to send. For some unknown reason my NSURLConnection is never failing, no matter how short I set the timeoutInterval . // Create the URL request NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://www.tumblr.com/api/write"] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:0.00000001]; /* Populate the request, this part works fine */ [NSURLConnection connectionWithRequest:request delegate

How to send Asynchronous URL Request?

喜欢而已 提交于 2019-11-26 20:22:05
I would like to know how do I get a return value 1 or 0 only.... back from an URL request asynchronously. currently I do it in this way: NSString *UTCString = [NSString stringWithFormat:@"http://web.blah.net/question/CheckQuestions?utc=%0.f",[lastUTCDate timeIntervalSince1970]]; NSLog(@"UTC String %@",UTCString); NSURL *updateDataURL = [NSURL URLWithString:UTCString]; NSString *checkValue = [NSString stringWithContentsOfURL:updateDataURL encoding:NSASCIIStringEncoding error:Nil]; NSLog(@"check Value %@",checkValue); this works, however it is blocking my main thread till I got a reply back from

NSURLConnection/NSURLRequest gzip support

假装没事ソ 提交于 2019-11-26 19:23:37
问题 Does anyone knows if NSURLConnection/NSURLRequest have support for gzip requests. If does, can you provide more information? 回答1: although it does not seem to be documented, there is evidence that NSURLConnection does have transparent gzip support. meaning that if the server supports gzip encoding, and your request has an Accept-Encoding header containing gzip *, the server will send a gzipped response, which NSURLConnection will automatically decode. * NSURLRequest might add that header by