nsurlrequest

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

Getting data out of completionHandler in Swift in NSURLConnection

夙愿已清 提交于 2019-12-02 17:42:20
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, completionHandler:{ (response: NSURLResponse!, data: NSData!, error: NSError!) -> Void in /* this next line

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:

webview having trouble with redirects

百般思念 提交于 2019-12-02 10:53:11
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? 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 you need to change to another site, just create a global NSString var like so // for site name NSString

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

Get content of webservice

杀马特。学长 韩版系。学妹 提交于 2019-12-02 09:08:44
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 . 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: Using NSURLConnection Use NSURLConnection in synchronous mode: // Error checks omitted NSURL *URL = [NSURL

How I know the the posting data goes correctly

对着背影说爱祢 提交于 2019-12-02 04:45:02
-(IBAction)clicked:(id)sender{ NSString *CIDString = cID.text; NSURL *url = [NSURL URLWithString:@"http://localhost:8080/test/?"]; NSString *postData = [NSString stringWithFormat:@"companyID=%@",CIDString]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[url standardizedURL] cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:60]; [request setHTTPMethod:@"POST"]; [request setValue:@"application/x-www-form-urlencoded; charset=utf-8" forHTTPHeaderField:@"Content-Type"]; [request setHTTPBody:[postData dataUsingEncoding:NSUTF8StringEncoding]]; [self

How to send a URL request as 'Referer'

醉酒当歌 提交于 2019-12-02 01:44:04
问题 I have an app which existed as an iPhone app first and now as an Android app. One of the functions is to load a web page which bypasses the security login by passing a string as Referer. The code for the iPhone is as follows - NSMutableURLRequest *request = [NSMutableURLRequest new]; [request setValue:@"http://myweb.com/" forHTTPHeaderField:@"referer"]; [request setURL:[NSURL URLWithString:@"http://www.theirweb.com/meetings/meetings.plx?CID=TEST2012&O=Generic&Key=4s6p2wz9"]]; [htmlDoc

Swift 3: URLSession / URLRequest Not Working

雨燕双飞 提交于 2019-12-01 16:07:47
I am still trying to convert our application from Swift 2 over to Swift 3 because I am being forced to since all of our Apple devices are now running iOS 10. I have gone through the code conversion and thought I was doing well however, while attempting to debug my JSON issues (posted in another question), I am now dealing with requests not even being sent. let params: [String:AnyObject] = [ "email":"\(self.preferences.string(forKey: "preference_email")!)" as AnyObject ] let requestParams: [String:AnyObject] = [ "action":"601" as AnyObject, "params":params as AnyObject ] do { let requestObject

How can I wait for a NSURLConnection delegate to finish before executing the next statement?

蓝咒 提交于 2019-12-01 12:04:43
This has been a hard one to search. I found a similar question, iOS 5 Wait for delegate to finish before populating a table? , but the accepted answer was 'Refresh the table view,' and that does not help me. The other results I found tended to be in c#. I have an app that streams from iPhone to Wowza servers. When the user hits record, I generate a unique device id, then send it to a PHP script on the server that returns a JSON document with configuration settings (which includes the rtmp dump link). The problem is, the delegate methods are asynchronous, but I need to get the config settings