nsurlconnection

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

Post data in Objective C using Json

拟墨画扇 提交于 2019-11-26 20:04:01
I am trying to post data to a PHP web service. I am familiar doing this in html using query $.post but I am very much stumped trying this in objective C. I tried several blogs & questions found on stackoverflow. I finally came up with the following code: NSString *jsonRequest = [NSString stringWithFormat:@"{\"Email\":\"%@\",\"FirstName\":\"%@\"}",user,fname]; NSLog(@"Request: %@", jsonRequest); NSURL *url = [NSURL URLWithString:@"http:myurl..."]; NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url]; NSData *requestData = [NSData dataWithBytes:[jsonRequest UTF8String]

Add NSURLConnection loading process on UIProgressView

不羁岁月 提交于 2019-11-26 20:03:55
问题 I created a UIProgressView . But i used NSTimer to UIProgressView's process . Now I need to integrate UIProgressView process, when URL is loading. UIProgressView's size will be depends upon the NSURLConnection's data. I used the following code to NSURLConnection . -(void)load { NSURL *myURL = [NSURL URLWithString:@"http://feeds.epicurious.com/newrecipes"]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:myURL cachePolicy:NSURLRequestReloadIgnoringLocalCacheData

iPhone sending POST with NSURLConnection

霸气de小男生 提交于 2019-11-26 19:54:07
I'm having some problems with sending POST data to a PHP script with NSURLConnection. This is my code: const char *bytes = [[NSString stringWithFormat:@"<?xml version=\"1.0\"?>\n<mydata>%@</mydata>", data] UTF8String]; NSURL *url = [NSURL URLWithString:@"http://myurl.com/script.php"]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; [request setHTTPMethod:@"POST"]; [request setHTTPBody:[NSData dataWithBytes:bytes length:strlen(bytes)]]; NSURLResponse *response; NSError *err; NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:

how to use sendAsynchronousRequest:queue:completionHandler:

六眼飞鱼酱① 提交于 2019-11-26 19:28:31
Two part question Part one: I am trying to create an ASynchronous request to my database. I am currently doing it Synchronously however I want to learn both ways to better my understanding of whats going on. Currently I have set up my Synchronous call like this. - (IBAction)setRequestString:(NSString *)string { //Set database address NSMutableString *databaseURL = [[NSMutableString alloc] initWithString:@"http://127.0.0.1:8778/instacodeData/"]; // imac development //PHP file name is being set from the parent view [databaseURL appendString:string]; //call ASIHTTP delegates (Used to connect to

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

NSURLConnection delegate methods are not called

≯℡__Kan透↙ 提交于 2019-11-26 19:17:29
问题 I am trying to create a simple NSURLConnection to communicate with a server using a GET request. Connection works well, but delegates methods of NSURLConnection are never called.. Here is what am doing: NSString *post = [NSString stringWithFormat:@"key1=%@&key2=%@&key3=%f&key4=%@", val1, val4, val3, val4]; NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease] ; [request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://www.domain.com/demo/name/file.php?

Asynchronous request to the server from background thread

天涯浪子 提交于 2019-11-26 18:48:47
问题 I've got the problem when I tried to do asynchronous requests to server from background thread. I've never got results of those requests. Simple example which shows the problem: @protocol AsyncImgRequestDelegate -(void) imageDownloadDidFinish:(UIImage*) img; @end @interface AsyncImgRequest : NSObject { NSMutableData* receivedData; id<AsyncImgRequestDelegate> delegate; } @property (nonatomic,retain) id<AsyncImgRequestDelegate> delegate; -(void) downloadImage:(NSString*) url ; @end

NSURLConnection sendAsynchronousRequest can't get variable out of closure

大兔子大兔子 提交于 2019-11-26 17:53:41
I'm trying to get a simple text response from a PHP page using POST. I have the following code: func post(url: String, info: String) -> String { var URL: NSURL = NSURL(string: url)! var request:NSMutableURLRequest = NSMutableURLRequest(URL:URL) var output = "Nothing Returned"; request.HTTPMethod = "POST"; var bodyData = info; request.HTTPBody = bodyData.dataUsingEncoding(NSUTF8StringEncoding); NSURLConnection.sendAsynchronousRequest(request, queue: NSOperationQueue.mainQueue()){ response, data, error in output = (NSString(data: data, encoding: NSUTF8StringEncoding))! } return output } While

How to use iOS Reachability

拜拜、爱过 提交于 2019-11-26 17:35:38
问题 I'm developing an iPhone app that uses the network. The iPhone communicate with my server via HTTP request and should work on WiFi and 3G. I currently use NSURLConnection initWithRequest to send async requests to my server and get responses (but I will soon move to work with ASIHTTPRequest library) I understood that with this kind of apps(apps that requires internet connection) I should (must?) use Reachability. After searching the web and looking at Apple's Reachability example code i still