nsurlconnection

NSURLConnection and grand central dispatch

假如想象 提交于 2019-11-27 02:38:28
Is it advisable to wrap up NSUrlConnection in a gcd style blocks and run it on a low_priority queue? I need to ensure that my connections are not happening on the main thread and the connections need to be asynchronous. I also need several simultaneous requests to go at once. If I go the gcd route, I'm not sure which thread the NSUrlConnectionDelegate methods get invoked on. NSURLConnection relies on delegates so once the connection is complete, whatever wrapper class that handles it will need to invoke its caller. I'm not certain how to deal with all of the various callbacks that are invoked

iOS Develoment: Why is my NSURLConnection failing with a “bad URL” error for only some users?

依然范特西╮ 提交于 2019-11-27 02:02:20
问题 I have an iOS app that requests JSON data from my Rails 3 app, hosted on Heroku, and it works great on my device and for many other users, except one. I have one user who has told me that my app fails to retrieve the JSON data, so I had her send me some log data and the log showed the NSURLConnection delegate method didFailWithError is being called and the error description reads "bad URL" . Why is this error occurring and why is it ONLY occurring on just some devices instead of all devices?

Sending a JSON via POST in NSURLRequest

◇◆丶佛笑我妖孽 提交于 2019-11-27 01:24:59
问题 I have a problem with sending a JSON to a Server with REST API. This is the code i use: NSString *jsonPostBody = [NSString stringWithFormat:@"'json' = '{\"user\":{\"username\":" "\"%@\"" ",\"password\":" "\"%@\"" "}}'", [username stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding], [password stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; NSData *postData = [jsonPostBody dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES]; NSString *apiPathParams =

why [response expectedContentLength] always return -1

╄→гoц情女王★ 提交于 2019-11-27 01:05:10
-(void) connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response { [UIApplication sharedApplication].networkActivityIndicatorVisible = YES; if([recievedData length]) [ recievedData setLength:0 ]; download_size =[response expectedContentLength]; } I have this code. download_size is NSInteger. expectedContentLenght always return: -1. Maybe someone know why? I tried use long, but effect was the same. Thanks for help. The expected content length is only set when the server provides it, such as by a Content-Length response header. A -1 size means the expected content

NSURLConnection sendAsynchronousRequest:queue:completionHandler: making multiple requests in a row?

做~自己de王妃 提交于 2019-11-26 23:23:18
I have been using NSURLConnection's sendAsynchronousRequest:queue:completionHandler: method which is great. But, I now need to make multiple requests in a row. How can I do this while still using this great asychronous method? There's lots of ways you can do this depending on the behavior you want. You can send a bunch of asynchronous requests at once, track the number of requests that have been completed, and do something once they're all done: NSInteger outstandingRequests = [requestsArray count]; for (NSURLRequest *request in requestsArray) { [NSURLConnection sendAsynchronousRequest:request

Handling redirects correctly with NSURLConnection

99封情书 提交于 2019-11-26 22:45:37
问题 For the purposes of this, I'm going to pretend the original url is http://host/form and the new url is https://host/form . (Note that before I ship this, both URLs are going to be secure. However, the nonsecure-to-secure seems like a convenient redirect to test this on.) I'm accessing a web API using NSURLConnection that redirects me. Basically, I want to take everything I just submitted to http://hostaform and re-submit it to https://host/form . I thought this would be the default behavior,

error handling with NSURLConnection sendSynchronousRequest

拜拜、爱过 提交于 2019-11-26 22:43:55
问题 how can i do better error handling with NSURLConnection sendSynchronousRequest? is there any way i can implement - (void)connection:(NSURLConnection *)aConn didFailWithError:(NSError *)error i have a nsoperation queue which is getting data in background thats why i have sync request. and if i have to implement async request then how can i wait for request to get complete. because that method can't proceed without data. 回答1: -sendSynchronousRequest:returningResponse:error: gives you a way to

NSMutableURLRequest timeout interval not taken into consideration for POST requests

感情迁移 提交于 2019-11-26 22:21:41
I have the following problem. On a NSMutableURLRequest using the HTTP method POST the timeout interval set for the connection is ignored. If the internet connection has a problem (wrong proxy, bad dns) the url request fails after about 2-4 minutes but not with NSLocalizedDescription = "timed out"; NSUnderlyingError = Error Domain=kCFErrorDomainCFNetwork Code=-1001 UserInfo=0x139580 "The request timed out. If the http method used is GET it works fine. The connection is async over https . NSURL *url = [NSURL URLWithString:urlString]; NSMutableURLRequest *request = [NSMutableURLRequest

NSURLSession: How to increase time out for URL requests?

别说谁变了你拦得住时间么 提交于 2019-11-26 22:04:38
I am using iOS 7's new NSURLSessionDataTask to retrieve data as follows: NSURLSession *session = [NSURLSession sharedSession]; NSURLSessionDataTask *dataTask = [session dataTaskWithRequest: request completionHandler: ^(NSData *data, NSURLResponse *response, NSError *error) { // }]; How can I increase the time out values to avoid the error "The request timed out" (in NSURLErrorDomain Code= -1001 )? I have checked the documentation for NSURLSessionConfiguration but did not find a way to set the time out value. Thank you for your help! ObjC NSURLSessionConfiguration *sessionConfig =

Simpliest solution to check if File exists on a webserver. (Swift)

早过忘川 提交于 2019-11-26 21:04:13
问题 There are a lot of discussion about this and I understand the solution to use the delegate method and check the response "404": var request : NSURLRequest = NSURLRequest(URL: url) var connection : NSURLConnection = NSURLConnection(request: request, delegate: self, startImmediately: false)! connection.start() func connection(didReceiveResponse: NSURLConnection!, didReceiveResponse response: NSURLResponse!) { //... } But I would like to have a simple solution like: var exists:Bool=fileexists