nsurlrequest

NSAppTransportSecurity UIWebView issue

核能气质少年 提交于 2019-12-24 16:16:02
问题 I have these lines in my info.plist file: <key>NSAppTransportSecurity</key> <dict> <key>NSExceptionDomains</key> <dict> <key>mysebserver.com</key> <dict> <key>NSIncludesSubdomains</key> <true/> <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key> <true/> <key>NSTemporaryExceptionMinimumTLSVersion</key> <string>TLSv1.1</string> </dict> </dict> </dict> So it works perfect with my API calls. In my view controller I have UIWebView that tries to display web content: NSURLRequest* request =

How to pass an BIG5 chinese characters in objective-c

纵然是瞬间 提交于 2019-12-24 09:36:57
问题 I want to pass an Chinese characters (BIG5) in NSURLConnection in my request but it shows an error Domain=NSURLErrorDomain Code=-1000 "bad URL" UserInfo=0xa17a750 {NSUnderlyingError=0xa17ffa0 "bad URL", NSLocalizedDescription=bad URL} 回答1: You should escape your string by using -[NSString stringByAddingPercentEscapesUsingEncoding:] method before using it in URL. And I suspect you should also convert your big5 string to utf8 before escaping. EDIT: To use BIG5 you can use this: NSStringEncoding

Unable to get responses from local server when connecting via iOS device

谁说我不能喝 提交于 2019-12-24 08:39:35
问题 Im using AFNetworking to retrieve items from a basic rails server in a simple iOS project. When I make the request in the simulator, everything works smoothly. However, when I make the same request while running the project on my device, I'm getting a frustrating error. I understand that I cannot connect to localhost directly from my device and therefore need to use my ip address, which I am doing. This is the weird part: when I make a request to the server, I can see in my terminal that the

Waiting on asynchronous methods using NSCondition

纵然是瞬间 提交于 2019-12-24 00:58:09
问题 I am downloading four plist files asynchronously over the internet. I need to wait until all four files are downloaded, until I either on the first run, push a UIViewController, or on all subsequent runs, refresh the data, and reload all my UITableViews. On the first run, everything works perfectly. When refreshing though, all four url requests are called, and started, but never call their completion or failure blocks, and the UI freezes. Which is odd since I preform all operations in a

Xcode8 beta 6 - URLSession with completionHandler argument not working

百般思念 提交于 2019-12-24 00:48:46
问题 I can't seem to use this method in my code at all after changing from beta 5 til beta 6. open func dataTask(with request: URLRequest, completionHandler: @escaping (Data?, URLResponse?, Error?) -> Swift.Void) -> URLSessionDataTask My code: let task = self.createSession().dataTask(with: request, completionHandler: { (data, response, error) in self.handleTaskResult(data: data, response: response, error: error, completionHandler: completionHandlerIncoming) }) I get that "Cannot invoke 'dataTask'

iOS swift post request with binary body

血红的双手。 提交于 2019-12-23 18:33:57
问题 I want to make a POST request from iOS (swift3) which passes a chunk of raw bytes as the body. I had done some experimenting which made me thought the following worked: let url = URL(string: "https://bla/foo/bar")! var request = URLRequest(url: url) request.httpMethod = "POST" request.httpBody = Data(hex: "600DF00D") let session = URLSession.shared let task = session.dataTask(with: request) { (data, response, error) in "DATA \(data ?? Data()) RESPONSE \(response) ERROR \(error)".print() }

NSURLRequest setValue: forHTTPHeaderField:@“Authorization” not working

主宰稳场 提交于 2019-12-23 00:25:53
问题 I try to make an authenticate call to the twitter API with the Application only Authentication API NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url] cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:20.0]; [request setHTTPMethod:@"POST"]; [request setValue:@"application/x-www-form-urlencoded;charset=UTF-8" forHTTPHeaderField:@"Content-Type"]; [request setValue:@"Some App Name" forHTTPHeaderField:@"User-Agent"]; [request setValue

NSURLRequest setValue: forHTTPHeaderField:@“Authorization” not working

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-23 00:24:10
问题 I try to make an authenticate call to the twitter API with the Application only Authentication API NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url] cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:20.0]; [request setHTTPMethod:@"POST"]; [request setValue:@"application/x-www-form-urlencoded;charset=UTF-8" forHTTPHeaderField:@"Content-Type"]; [request setValue:@"Some App Name" forHTTPHeaderField:@"User-Agent"]; [request setValue

NSURLRequest setValue: forHTTPHeaderField:@“Authorization” not working

五迷三道 提交于 2019-12-23 00:24:04
问题 I try to make an authenticate call to the twitter API with the Application only Authentication API NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url] cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:20.0]; [request setHTTPMethod:@"POST"]; [request setValue:@"application/x-www-form-urlencoded;charset=UTF-8" forHTTPHeaderField:@"Content-Type"]; [request setValue:@"Some App Name" forHTTPHeaderField:@"User-Agent"]; [request setValue

Cocoa File Upload with Progress Bar

為{幸葍}努か 提交于 2019-12-22 17:56:01
问题 (This is really a double-whammy in terms of questions, since there really is two serperate questions, but they kinda belong together.) First Question: How would I go about uploading a file (I have an NSData object containing the file's contents already) using POST, while displaying the upload progress in an NSProgressIndicator ? Much like one can do bytesReceived in NSURLDownload , but this time tracking how many bytes have already been sent using POST. Second Question: While I have this