unable to download zip file using http post method

always showing network connection lost error with following logs

 

 

2017-12-07 11:59:37.052511+0530 ProvisioningEffort[1912:80612] TIC Read Status [2:0x60000017bcc0]: 1:57

2017-12-07 11:59:37.053975+0530 ProvisioningEffort[1912:80612] Task <0CF85E1C-ADC5-4A06-90C5-1074BE96C433>.<1> HTTP load failed (error code: -1005 [1:57])

2017-12-07 11:59:37.055003+0530 ProvisioningEffort[1912:80993] Task <0CF85E1C-ADC5-4A06-90C5-1074BE96C433>.<1> finished with error – code: -1005

it is working fine while downloading a text file but the issue is while downloading zip file


func performSyncRequest()

{

let documentsUrl = FileManager.default.urls(for: .libraryDirectory, in: .userDomainMask).first

let url = syncUrl.prepareSyncURL()

var urlrequest = URLRequest(url: url)

urlrequest.httpMethod = "POST"

urlrequest.addValue("application/json", forHTTPHeaderField: "Content-Type")

let requestBody = syncUrl.prepareRequestBody()

guard let httpBody = try? JSONSerialization.data(withJSONObject: requestBody, options: [])

else

{

return

}

urlrequest.httpBody = httpBody

do

{

let convertedString = String(data: httpBody, encoding: String.Encoding.utf8)

print("Sync Request Body: (convertedString!)")

}

let downloadTask = URLSession.shared.downloadTask(with: urlrequest, completionHandler: {

url,response,error in if error == nil

{

do

{

try FileManager.default.copyItem(at:url!, to: self.documentsUrl!) print(self.documentsUrl!)

} catch (let writeError)

{

print("error writing file (self.documentsUrl!) : (writeError)")

}

}

}) downloadTask.resume()

}

Powered by WPeMatico

About

You may also like...

Comments are closed.