nsurlsession

Body of NSMutableRequest consisting of base64encodeString gets truncated while sending as a string

橙三吉。 提交于 2019-12-12 03:09:01
问题 Recently, I am doing a NSUrlSession task to upload multiple images to the backend . I appended all the images in .png representation in an array. I converted the whole array into a base64 String format and tried to send the whole body as a string. Conversion of imageArray to String - let imageArrayData: NSData = NSKeyedArchiver.archivedDataWithRootObject(imageArray) let imageArrayBase64String = imageArrayData.base64EncodedStringWithOptions(NSDataBase64EncodingOptions(rawValue: 0)) Here

NSURLSession completion handler very slow

…衆ロ難τιáo~ 提交于 2019-12-12 02:59:29
问题 When I run the following code, I can print a response almost immediately, however, it can take ten seconds or more to appear in my view. It seems like most similar problems are caused by the session and the handler being on different threads. But why does it work eventually? Very confused... func downloadDetails(completed: DownloadComplete) { let url = NSURL(string: _detailsURL)! let session = NSURLSession.sharedSession() let task = session.dataTaskWithURL(url) { (data, response, error) ->

how to set the authorization token based on this curl?

馋奶兔 提交于 2019-12-12 02:25:49
问题 I want add a token for Authorisation to the header. Here it is the curl that my backend ask me to set before any interaction: curl -H 'Authorization: Token token="replace-with-token"' http://domain.com/topic here is my code: [config setHTTPAdditionalHeaders:@{@"Authorization":@"token=\"4959a0bc00a15e335fb6\""}]; I keep getting "HTTP Token: Access denied." does any one know reason? 回答1: I believe it would be this?: [config setHTTPAdditionalHeaders:@{@"Authorization":@"Token token=\

NSURLSession Background File Upload using Bound Streams

走远了吗. 提交于 2019-12-12 01:59:40
问题 History: I am working on a project for which we need to support: Background Upload of files using NSURLSession . The server expects file to be uploaded using Content-Type: multipart/form-data Previously, I was using NSURLConnection with bound pair of Streams as depicted in this Apple Sample. Now, I wish to follow similar approach with NSURLSession(Background Session) by using uploadTaskWithStreamedRequest :. I have written a small stand-alone iOS Sample + a PHP server to validate my concept.

SOAP request using NSURLSession Objective C or SWIFT

谁说胖子不能爱 提交于 2019-12-12 01:36:57
问题 How i can perform SOAP request using NSURLSession ? Please find request format for SOAP . <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:pm="http://sampleurl.com/webservices/pm"> <soapenv:Header/> <soapenv:Body> <pm:start> <username>awdmmappadmin1</username> <password>password</password> <completedDate>2016-04-25T13:37:34.699Z</completedDate> <gameMinutes>2</gameMinutes> <gameMoves>14</gameMoves> <gameSeconds>33</gameSeconds> <gameTimeSec>153</gameTimeSec>

How to use NSURLSession to post some properties and a image

独自空忆成欢 提交于 2019-12-12 00:42:24
问题 I have a node.js as backend server. And it has a post method accept a title param and a latitude and longitude param and a image. So, I am not only post a image but with other params together. In the node.js, title -> uitextview's text latitude & longitude - > cllocation and a image. the node.js corresponding method is a form. How to use NSURLSessionUploadTask to post them to the server. 回答1: A file upload with additional parameters will be usually accomplished using a HTTP message whose

Swift: How to add Dictionary format in forHTTPHeaderField in GET request

拟墨画扇 提交于 2019-12-11 15:59:11
问题 In GET request, I am trying to add header. request.setValue(value: String?, forHTTPHeaderField: "SessionInfo") But, SessionInfo value is in [String : Any] Attempt 1: func SO_Function() { let service_url = WebService.sharedManager().serviceURL let getMenuURL = service_url + "/MyPage/FileDownload.ashx" var convertedString = "" do { let data1 = try JSONSerialization.data(withJSONObject: WebService.sharedManager().mobInfoDict, options: []) convertedString = String(data: data1, encoding: .utf8)!

Cannot call value of non-function type 'URLSession' error with mockURLSession

蓝咒 提交于 2019-12-11 14:48:56
问题 I'm trying to unit test URLSession delegates with mockData. This is the delegate function that is being tested: urlSession(_ session: URLSession, task: URLSessionTask, didCompleteWithError error: Error?) This is the unit test so far: func test_urlSession(){ let mockSession = MockURLSession(mockResponse: MockURLSession().successHttpURLResponse(request: self.urlRequest!) as! HTTPURLResponse) //error here sut?.urlSession(mockSession, task: MockURLSessionDataTask, didCompleteWithError: Error) }

How to add data to HTTPBody with PUT method in NSURLSession?

坚强是说给别人听的谎言 提交于 2019-12-11 13:29:06
问题 This is my code. It's working with POST but not with PUT. let url:NSURL = NSURL(string: urlApi)! let session = NSURLSession.sharedSession() let request = NSMutableURLRequest(URL: url) request.HTTPMethod = "PUT" request.cachePolicy = NSURLRequestCachePolicy.ReloadIgnoringCacheData request.addValue("a5f96d8c01000194c639d6b5f3b199eb", forHTTPHeaderField: "token") request.addValue("application/json", forHTTPHeaderField: "Accept") let params:[String: AnyObject] = ["id" : 296,"name" : "asdad",

How send post data with text parameter and image file?

拥有回忆 提交于 2019-12-11 13:25:58
问题 I make an application that allows user to upload image and several to our server. If I just post text data my code successfully post data to the server but when I try to post text data with image data, my server throw an exception. here is my code: class func Enroll(image: UIImage, date: String, studentid: String, guardianid:String, type:String){ //date,student_id,type,guardian_id,image, type var textBody : String? let imageData = UIImagePNGRepresentation(image) let boundary = NSString(format