nsurlrequest

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"

Getting data out of completionHandler in Swift in NSURLConnection

时间秒杀一切 提交于 2019-12-03 04:32:36
问题 I am trying to write a function that will execute an asynchronous GET request, and return the response (as any data type, but here it is as NSData). This question is based on: How to use NSURLConnection completionHandler with swift func getAsynchData() -> NSData { var dataOutput : NSData let url:NSURL = NSURL(string:"some url") let request:NSURLRequest = NSURLRequest(URL:url) let queue:NSOperationQueue = NSOperationQueue() NSURLConnection.sendAsynchronousRequest(request, queue: queue,

How to send GEt request to PHP in iOS

て烟熏妆下的殇ゞ 提交于 2019-12-03 00:51:00
Hi i have problem in sending GET request to a PHP, same PHP works fine when running it in web browser here are the code snippet of both the PHP and Obj-C PHP $var1=$_GET['value1']; $var2=$_GET['value2']; when i call this in browser like http://sample.com/sample.php?value1=hi&value2=welcome it works fine, but from obj c i could't get succeed obj C NSString *url =[NSString stringWithFormat:@"http://sample.com/sample.php"]; NSData *data = [@"sample.php" dataUsingEncoding:NSUTF8StringEncoding]; NSLog(@"%@",url); NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:[NSURL URLWithString

Constantly growing memory allocation while fetching images over HTTP in iOS

陌路散爱 提交于 2019-12-02 23:07:13
I am implementing an iOS App that needs to fetch a huge amount of images over HTTP. I've tried several approaches but independently what I do, Instuments shows constantly increasing memory allocations and the App crashes sooner or later when I run it on a device. There are no leaks shown by Instruments. So far I have tried the following approches: Fetch the images using a synchronous NSURLConnection within an NSOperation Fetch the images using a asynchronous NSURLConnection within an NSOperation Fetch the images using [NSData dataWithContentsOfURL:url] in the Main-Thread Fetch the images using

App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure.

折月煮酒 提交于 2019-12-02 22:49:25
问题 Supposedly temporary exceptions can be configured via your app's Info.plist file. Following other answers, I added this entry to the info.plist but it does not help (even worse, after I changed the xml file I get a permission error when I attempt to run the app on my iPhone but not on the simulator - but that is a different problem.) <key>NSAppTransportSecurity</key> <dict> <key>NSAllowsArbitraryLoads</key> <true/> </dict> 回答1: From Project Navigator click your project's name. Now, on the

How can I get NSURLResponse body?

試著忘記壹切 提交于 2019-12-02 21:54:30
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 ? Why do you cancel the connection? After all, 404 can have content body as well. Just don't cancel it, and let the program call the next delegate NSURLConnection method. When the data

webview having trouble with redirects

梦想与她 提交于 2019-12-02 21:12:20
问题 NSURL *urlString = [NSURL URLWithString:urlAddress]; //URL Requst Object NSURLRequest *requestObj = [NSURLRequest requestWithURL:urlString]; //Load the request in the UIWebView. [self.webview loadRequest:requestObj]; The UIWebView is having trouble with redirects. How can I make sure the uiwebview handles redirects properly? 回答1: In order to do a redirect from one site to another, just load your website, but add a BOOL var for checking if the right page is loaded. BOOL page1Loaded; then, if

Resume download functionality in NSURLConnection

情到浓时终转凉″ 提交于 2019-12-02 21:04:40
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? 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. To resume downloading and get the rest of the file you can set the Range value in HTTP request header by doing something like this: - (void)downloadFromUrl:

Unsupported URL in NSURLRequest

这一生的挚爱 提交于 2019-12-02 20:07:53
If I run this request from my terminal I can see the JSON requests as normally: curl -XGET 192.168.0.6:8888/scripts/data/backend2/index.php/name/_all My code for the NSURlRequest is this: NSURLRequest *request = [NSURLRequest requestWithURL: [NSURL URLWithString:@"192.168.0.6:8888/scripts/data/backend2/index.php/name/_all"]]; [[NSURLConnection alloc] initWithRequest:request delegate:self]; And I am getting this error: didFailWithError 2013-11-29 22:31:08.164 Ski Greece[607:a0b] Connection failed: Error Domain=NSURLErrorDomain Code=-1002 "unsupported URL" UserInfo=0xcd042d0

Using NSURLRequest to pass key-value pairs to PHP script with POST

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-02 18:44:23
I'm fairly new to objective-c, and am looking to pass a number of key-value pairs to a PHP script using POST. I'm using the following code but the data just doesn't seem to be getting posted through. I tried sending stuff through using NSData as well, but neither seem to be working. NSDictionary* data = [NSDictionary dictionaryWithObjectsAndKeys: @"bob", @"sender", @"aaron", @"rcpt", @"hi there", @"message", nil]; NSURL *url = [NSURL URLWithString:@"http://myserver.com/script.php"]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; [request setHTTPMethod:@"POST"];