0
urlとリクエストボディでサーバをリクエストする必要がありますが、レスポンスはzipファイルになります。私はzipファイルをダウンロードして使用する必要があります。ファイルを保存して再利用する方法を知っておく必要がありますが、次のエラーが発生します。リクエストボディでurlsessionを使ってファイルをダウンロードするには
タスク< 11E36FDA-1408-474D-B576-A222DEBA53B2>。 < 3>エラーで終了 - コード:問題は、zipファイルをダウンロードしようとしている間-1005
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 {
//some code
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()
}
ダウンロードしたファイルは、self.documentsURLにコピーされているようです。あなたはそのファイルのコピーを使用できませんか? – pushkarnk
documentslrlにはファイルがありません –
このプログラムはあなたのものと似ていますが、上記のリンクにhttps://gist.github.com/pushkarnk/dabe290e9990abf47d34d626d2238fbb – pushkarnk