nsurlconnection

Do UIWebView and NSURLConnection share cookie storage?

非 Y 不嫁゛ 提交于 2019-12-03 09:19:29
问题 I'm building an iOS app that uses Google App Engine for the backend. Google provides an HTML login site that stores an authentication cookie. If I visit that site in a UIWebView, and the user logs in, will those cookies be in storage where they will be picked up by a NSURLConnection when making a request to the same site? 回答1: The cookie of the UIWebView will be stored in a sandboxed cookie storage accessible through NSHTTPCookieStorage sharedHTTPCookieStorage] . You can use this cookie

When does NSURLSession run?

给你一囗甜甜゛ 提交于 2019-12-03 08:29:55
I have a situation in which when the device receives a push notification, I would send a NSURLSession combined with a NSURLConnection . I have a couple of questions regarding NSURLSession . Does NSURLSession's Data Task automatically resume in the background, if internet connection is lost? Does NSURLSession automatically attempt to complete the task if there is no internet initially, or does the session just return with an error? Looks like it's down to you to handle the retry. When any task completes, the NSURLSession object calls the delegate’s URLSession:task:didCompleteWithError: method

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

Asynchronous request example

自闭症网瘾萝莉.ら 提交于 2019-12-03 07:30:23
问题 NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http:///]; NSURLRequest *req = [[NSURLRequest alloc]initWithURL:url]; NSURLConnection *con = [[NSURLConnection alloc]initWithRequest:req delegate:self startImmediately:YES]; In my project I used sendSynchronousRequest on NSURLConnection . It gives me crash sometimes. So I convert this code to AsynchronousRequest . I could not find suitable code. Somebody give me link or post code which suitable to my code. Any hep will be

Updating iPhone Reachability on Network Changes

萝らか妹 提交于 2019-12-03 06:20:45
Edit 23.5.11 I'm now wondering whether I'm over engineering this. When I use an online connection, I handle it properly - either: in the background with a progress or activity indicator showing and if it fails, I display a suitable message OR I call another application, either Safari or Maps which will then do its own check and fail if there is no connection. That leaves the user in that other app that has failed, which is not perfect tho. So if I do what I'm suggesting below and standard Reachability returns not reachable and I then have to do a NSURLConnection in case the radios have gone to

Using libcurl on iOS 5 as an alternative to NSURLConnection

我是研究僧i 提交于 2019-12-03 05:59:25
问题 Update: NSURLConnection now seems to properly support 100-Continue. In any case, this answer contains a link to the script to build libcurl for iOS/OSX. I'm having a bit of a hard time with NSURLConnection , given that it doesn't support Section 8.2.3 of RFC 2616 (HTTP/1.1). Basically the client needs to be able to support sending the header Expect: 100-Continue ; after sending the request headers, it must wait for a response from the server with the status code 100 before sending the POST /

Reading data from response header of NSURLConnection

爷,独闯天下 提交于 2019-12-03 05:36:30
问题 How can I read the data from the header sent by in the server response. I am using NSURLConnection to send the request. 回答1: If the URL is an HTTP URL, then the NSURLResponse that you receive in your connection's delegate's -connection:didReceiveResponse: method (or via another method) will be an NSHTTPURLResponse , which has an -allHeaderFields method that lets you access the headers. NSURLResponse* response = // the response, from somewhere NSDictionary* headers = [(NSHTTPURLResponse *

OAuth 2 bearer Authorization header

时间秒杀一切 提交于 2019-12-03 05:11:00
问题 With an update to the client's API the HTTPBasicAuthication method has been replace with a OAuth2 Bearer Authorization header. With the old API I would do the following: NSURLCredential *credential = [NSURLCredential credentialWithUser:self.account.username password:self.account.token persistence:NSURLCredentialPersistenceForSession]; NSURLProtectionSpace *space = [[NSURLProtectionSpace alloc] initWithHost:kAPIHost port:443 protocol:NSURLProtectionSpaceHTTPS realm:@"my-api"

POST with NSURLConnection - NO JSON

雨燕双飞 提交于 2019-12-03 05:04:06
I am trying to write an iPhone app in Objective-C. I need to POST data using NSURLConnection. Every example I can find deals with JSON; I do not need to use JSON. All I need to do is POST the data and get a simple 1 or 0 (succeed or fail) from a PHP script. Nothing more. I came across this code but I am not sure how to use it or modify it to not use JSON: - (void)performRequest { NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://someplace.com/"]]; [request setValue:@"Some Value" forHTTPHeaderField:@"Some-Header"]; [request setHTTPBody:@"{\

NSURLConnection Authorization Header not Working

拈花ヽ惹草 提交于 2019-12-03 05:02:49
问题 I am trying to send an OAuth access token in an HTTP header via NSURLConnection but it doesn't seem to be sending the header because the API keeps giving me an error saying that "must provide authorization token". This is the code that I am using: NSURL *aUrl = [NSURL URLWithString: @"http://generericfakeapi.com/user/profile"]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:aUrl cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:30.0]; [request addValue: