nsurlconnection

Using libcurl on iOS 5 as an alternative to NSURLConnection

…衆ロ難τιáo~ 提交于 2019-12-02 19:38: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 / PUT body. Furthermore, NSURLConnection (and consequently all libs that build on top of it) won't return

Perform POST request in Swift

纵饮孤独 提交于 2019-12-02 18:44:17
I am trying to do something like this: NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://google.com"]]; request.HTTPMethod = @"POST"; NSString *stringData = @"some data"; NSData *requestBodyData = [stringData dataUsingEncoding:NSUTF8StringEncoding]; request.HTTPBody = requestBodyData; NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request delegate:self]; This is what I have so far: var url = NSURL(string: "some url") var request = NSMutableURLRequest(URL: url) request.HTTPMethod = "POST" var dataString = "some data" var

OAuth 2 bearer Authorization header

一曲冷凌霜 提交于 2019-12-02 18:27:05
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" authenticationMethod:NSURLAuthenticationMethodHTTPBasic]; But this will not work with the Bearer header. Now normally I

Reading data from response header of NSURLConnection

♀尐吖头ヾ 提交于 2019-12-02 17:58:13
How can I read the data from the header sent by in the server response. I am using NSURLConnection to send the request. 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 *)response allHeaderFields]; // now query `headers` for the header you want In my case NSHTTPURLResponse *response

Get content of webservice

早过忘川 提交于 2019-12-02 17:38:28
问题 I've got an URL like here. When I type that into Safari's address bar I see an result like "Error" or "OK". So, how do I properly call that URL from within my code and get that result as a string? I've tried it with NSURLConnection , NSURLRequest and NSURLResponse but my response object is always nil . 回答1: The "response" in those classes refers to the protocol response (HTTP headers, etc.), not the content. To get the content, you have a few options: Use NSURLConnection in asynchronous mode:

NSURLConnection delegate

喜你入骨 提交于 2019-12-02 17:19:52
问题 REVISED... The crux of the app is communicating with a database server. Responses from the server to the app are all in XML. There are several screens. Example, screen 1 lists the user's information, screen 2 lists the user's past trades, allows new trades, and so on. Here is some code from my AppDelegate: StartViewController *svc = [[StartViewController alloc] init]; TradeViewController *tvc = [[TradeViewController alloc] init]; CashViewController *cvc = [[CashViewController alloc] init];

iOS background Location not sending http request

跟風遠走 提交于 2019-12-02 16:25:19
My app needs to track the users location in the background but it is failing to send a 'get' request. The http request gets sent immediately when the app comes to the foreground. I am using RestKit for all my network requests and I followed this tutorial to setup my background locations service. In my applicationDidEnterBackground -(void)applicationDidEnterBackground:(UIApplication *)application { self.bgLocationManager = [[CLLocationManager alloc] init]; self.bgLocationManager.delegate = self; [self.bgLocationManager startMonitoringSignificantLocationChanges]; NSLog(@"Entered Background"); }

How to download a file by using NSURLConnection?

僤鯓⒐⒋嵵緔 提交于 2019-12-02 13:16:47
I want to ask a question about the objective C. I want to download a .vcf file from a server (CardDav server) in iPhone application. After I read the API and library of the Apple Developer, I found that I should use the NSURLConnection Class . However, I don't know how to start the program. Therefore, I want to ask can anyone give me some tutorial or website reference (I mean the example) for me? Thank you very much. You can use this method: - (id)initWithRequest:(NSURLRequest *)request delegate:(id)delegate startImmediately:(BOOL)startImmediately More here and the delegate: - (void)connection

Consuming Custom Request Methods with iOS5

家住魔仙堡 提交于 2019-12-02 12:27:53
问题 My original question regarding Consuming Custom Request Methods with Android seems to have garnered very little attention -- I have converted it to an Android specific question So, quite simply, with iOS5 development, is it possible to consume custom request methods? If so, how. The "standard" set of request methods, as per RFC-2616 are: GET PUT POST DELETE TRACE CONNECT I would like to add another, called SEARCH . On the API, using PHP or Java, this is easy to implement in PHP. The

IOS sending post method data can access in php as get method

别说谁变了你拦得住时间么 提交于 2019-12-02 10:51:27
I am very new to iOS. I am trying to send data through post method to PHP. In PHP it can't take data like $_POST['data'] , but it takes $_GET['data'] . My iOS code is as follows. NSString *strURL = [NSString stringWithFormat:@"http://example.com/app_respond_to_job?emp_id=%@&job_code=%@&status=Worker-Accepted&comment=%@",SaveID2,txtJobcode1,alertTextField.text]; NSURL *apiURL = [NSURL URLWithString:strURL]; NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:apiURL]; [urlRequest setHTTPMethod:@"POST"]; NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest