nsurlsession

How to POST JSON data using NSURLSession in swift

蓝咒 提交于 2020-01-23 23:10:22
问题 I am stuck with the below code. How do I set the param and in post method? let params:[String:Any] = [ "email" : usr, "userPwd" : pwdCode] let url = NSURL(string:"http://inspect.dev.cbre.eu/SyncServices/api/jobmanagement/PlusContactAuthentication") let request = NSMutableURLRequest(URL: url!) request.setValue("application/json; charset=utf-8", forHTTPHeaderField: "Content-Type") request.HTTPBody = params<what should do for Json parameter> let task = NSURLSession.sharedSession()

How to POST JSON data using NSURLSession in swift

六月ゝ 毕业季﹏ 提交于 2020-01-23 23:09:14
问题 I am stuck with the below code. How do I set the param and in post method? let params:[String:Any] = [ "email" : usr, "userPwd" : pwdCode] let url = NSURL(string:"http://inspect.dev.cbre.eu/SyncServices/api/jobmanagement/PlusContactAuthentication") let request = NSMutableURLRequest(URL: url!) request.setValue("application/json; charset=utf-8", forHTTPHeaderField: "Content-Type") request.HTTPBody = params<what should do for Json parameter> let task = NSURLSession.sharedSession()

(kCFStreamErrorDomainSSL, -9814)

北城余情 提交于 2020-01-23 12:54:18
问题 I am trying to load a php script from a webview and am Having an error each and every time. NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9814) I updated my info.plist already to <key>NSAppTransportSecurity</key> <dict> <key>NSAllowsArbitraryLoads</key> <true/> </dict> Help me where I am going wrong. Here is the code that I have func webView(webView: UIWebView, shouldStartLoadWithRequest request: NSURLRequest, navigationType: UIWebViewNavigationType) -> Bool { let

(kCFStreamErrorDomainSSL, -9814)

孤街浪徒 提交于 2020-01-23 12:53:35
问题 I am trying to load a php script from a webview and am Having an error each and every time. NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9814) I updated my info.plist already to <key>NSAppTransportSecurity</key> <dict> <key>NSAllowsArbitraryLoads</key> <true/> </dict> Help me where I am going wrong. Here is the code that I have func webView(webView: UIWebView, shouldStartLoadWithRequest request: NSURLRequest, navigationType: UIWebViewNavigationType) -> Bool { let

Request Timeout NSURLSession

孤街浪徒 提交于 2020-01-23 12:39:17
问题 hello I used this below code to send a request to Server. How can I add the timeout in this function static func postToServer(url:String,var params:Dictionary<String,NSObject>, completionHandler: (NSDictionary?, String?) -> Void ) -> NSURLSessionTask { let request = NSMutableURLRequest(URL: NSURL(string: url)!) let session = NSURLSession.sharedSession() request.HTTPMethod = "POST" if(params["data"] != "get"){ do { let data = try NSJSONSerialization.dataWithJSONObject(params, options:

CFNetwork SSLHandshake failed (-9806) error using NSURLSession when app in background for an uploadTask

十年热恋 提交于 2020-01-21 04:54:11
问题 I am facing a CFNetwork SSL Handshake error while uploading a video file using NSURLSession UploadTask when the App is in background. There is no problem uploading the videos when the app is in foreground. Problem arises only when the app is in background. 回答1: Backgrounded NSURLSession 's handle a lot of things differently, including auth. I'd recommend you carefully read everything about background sessions and tasks in Apple's URL Loading System Programming Guide, particularly the section

NSURLSession returns different response than browser would, why?

妖精的绣舞 提交于 2020-01-14 14:33:48
问题 Any idea why NSURLSession returns this response: The authorization type you provided is not supported. Only Basic and OAuth are supported let username = "8r6nibK8Pe28WFhjTX1gGb1Rhhhc7xM02v7XKRPedL4" let password = "8r6nibK8Pe28WFhjTX1gGb1Rhhhc7xM02v7XKRPedL4" let loginString = NSString(format: "%@:%@", username, password) let loginData: NSData = loginString.dataUsingEncoding(NSUTF8StringEncoding)! let base64LoginString = loginData.base64EncodedStringWithOptions(.Encoding64CharacterLineLength)

NSURLSession doesn't return data in first call

此生再无相见时 提交于 2020-01-14 05:37:08
问题 In general, it is necessary to implement a class for the network. This is a class that will take a URL, and to give data. All this is done in order not to score an extra logic controllers. I encountered such a problem that when you first create a View, the data do not come. That's Network Class: private static var dataTask: NSURLSessionDataTask? private static var dataJSON: NSData? private static var sessionConfig: NSURLSessionConfiguration = { var configuration = NSURLSessionConfiguration

NSURLSession with upload stream - subclassing NSInputStream - com.apple.NSURLConnectionLoader exception

空扰寡人 提交于 2020-01-14 03:01:09
问题 Basic task I have some multiplatform library which is using some C++ stream interface. I have to use this stream interface to upload data by NSURLSession . My implementation should work on OS X and iOS (currently I'm testing on OS X) What I did Task looks quite simple and I was sure I will implement this quite fast. I have configured NSURLSession which is working fine if I'm using NSURLRequest with simple NSData . I'm trying to use stream like this: NSURLSessionDataTask *dataTask = [m_Private

Swift UIImage convert as PDF

有些话、适合烂在心里 提交于 2020-01-14 02:46:26
问题 In my App have to sale UIImage from iPad Gallery and convert into PDF and save on Server side. I can select the image and send it to server side , but Backend says that pdf is empty(null data) I also see the warning/error in my console : [discovery] errors encountered while discovering extensions: Error Domain=PlugInKit Code=13 "query cancelled" UserInfo={NSLocalizedDescription=query cancelled} Where am I going wrong? Thank you in advance! Code I tried //Opens gallery to select Image func