nsurlconnection

How can I get NSURLResponse body?

江枫思渺然 提交于 2019-12-04 08:15:12
问题 I'm writing an application that connect with a server using NSURLConnection . In the delegate method didreceiveresponse , if the status code is 404, I cancel the connection and I would like to show a message with a custom error that is generated in the server. The problem is that from response object, I only can get statuscode, headers, mimetype, etc. but no body. How do I get the body message from NSURLResponse ? 回答1: Why do you cancel the connection? After all, 404 can have content body as

Multiple async webservice requests NSURLConnection iOS

亡梦爱人 提交于 2019-12-04 08:10:30
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 UITableView. I suggest you use a Sync-Async Pattern on this problem. You need to implement two synchronous

With Objective-C, what is the best way to log in to a service and scrape content from the resulting page without an API?

此生再无相见时 提交于 2019-12-04 05:32:40
问题 One service I'm using doesn't have an API, but allows scraping, so I'm curious what the best way in iOS/Objective-C would be to do the following: Get user login credentials Submit them on the websites login page Grab specific links from the resulting page How does one circumvent issues such as the fact that the service does redirects you to a "Login successful, redirecting..." page before taking you to the content site? (This doesn't allow you to immediately scrape the resulting page.) For

Best way to handle multiple NSURL connections

我与影子孤独终老i 提交于 2019-12-04 01:32:32
问题 I am trying to create an xls sheet programmatically. To fill the sheet, I am making the multiple NSURLConnection around 100. Right now, my approach is : Make a connection and store the data into an array . This array has 100 objects. Now take the first object and call the connection . Store the data. And make the second connection with 2nd object in the array. This continues till the last object in the array. It takes on average 14 seconds to finish the 100 connections. Is there any way to

Stop an NSRunLoop

微笑、不失礼 提交于 2019-12-04 00:57:33
问题 I have a connection in a thread, so I add it to the run loop to get all data: [[NSRunLoop currentRunLoop] run]; [connection scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode]; But I can't find any way to stop it - (void)connectionDidFinishLoading:(NSURLConnection *)connection{ if([NSRunLoop currentRunLoop]){ [[NSRunLoop currentRunLoop] cancelPerformSelectorsWithTarget:self]; } [connection cancel]; } How can I stop this loop? 回答1: You can stop the runloop by Core

Stop current NSURLConnection

随声附和 提交于 2019-12-04 00:01:23
Currently, I am making an NSURLConnection whenever mySearchBar.text did change. I am experiencing an issue whereby if the user enters text too quickly, The respondData gets corrupted. So, I was wondering is there a way to check whether the same NSURLConnection is still loading? If yes, How do I drop the current connection and start a new one? Add a property for that NSURLConnection and before starting new connection, do: [self.conn cancel]; self.conn = nil; You could try to use asynchronous request. A good library for such call is ASIHTTPRequest . set [request cancel]; whenever you need to

When does NSURLConnection's initWithRequest return nil

时光总嘲笑我的痴心妄想 提交于 2019-12-03 22:39:29
Does anyone know in which situations initializing a NSURLConnection returns nil instead of the created connection. The documentation says it's possible but fails to specify when this happens. The method/message in question: [[NSURLConnection alloc] initWithRequest:request delegate:self]; - According to the NSURLConnection Class Reference: Return Value: The URL connection for the URL request. Returns nil if a connection can't be initialized. The URL Loading System Programming Guide says the following: If NSURLConnection can’t create a connection for the request, initWithRequest:delegate:

How to get image from server using NSUrlConnection [duplicate]

别等时光非礼了梦想. 提交于 2019-12-03 22:00:26
This question already has answers here : Closed 6 years ago . iOS: Download image from url and save in device (9 answers) How to get image from server by sending one parameter with url. GET HTTPRequest has to be use to send request. You can get image from server with specific path of that image with image name. UIImage* serverImage = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString: @"http://example.com/image_name.png"]]]; then you can use serverImage anywhere you want. Try to use this : -(UIImage*)getImageFromURLwithUrl:(NSString*)imgURLStr { NSMutableURLRequest

How to use HTTPS with NSURLConnection?

一笑奈何 提交于 2019-12-03 21:58:03
I'm interested in HTTPS with NSURLConnection . Is it possible to send a request, respond to a challenge and load the secure URL? Is there anything else that can be done with NSURLConnection via HTTPS? NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://monsite/mapage.php"] cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:60.0]; [request setHTTPMethod:@"POST"]; [request setHTTPBody:[[NSString stringWithFormat:@"score=222"] dataUsingEncoding:NSUTF8StringEncoding]]; [[UIApplication sharedApplication]

How many urlRequests are handled by nsurlconnection

三世轮回 提交于 2019-12-03 21:56:49
I have to call 20 urlReqests at a time after going through many websites i have found that 4 urlRequsts are handled after that next undergoing requests will encounter error that is timeout error.when i call 5 webservices in a loop first 4 webservices are executing and 5th gets timeout error.How to handle this situation Any help would be appreciated You can use NSOperationQueue for such tasks. Here is the sample code- Code for RequestManager.h :- #import <Foundation/Foundation.h> @protocol RequestManagerDelegate <NSObject> @optional - (void)requestForURL:(NSURL *)url tag:(NSString *)tag type: