sách gpt4 ai đã đi

GET thành công khi sử dụng NSURLSession nhưng không thành công khi sử dụng AFHTTPSessionManager

In lại 作者:行者123 更新时间:2023-11-30 13:08:38 30 4
mua khóa gpt4 Nike

我在使用预签名网址和 AFNetworking 3.0 从 S3 获取图像时遇到问题。我可以使用 NSMutableURLRequestPhiên NSURL 获取图像,但是当我使用 AFHTTPSessionManager 和相同的 NSMutableURLRequest 时,我收到 403 错误。 (我实际上想通过调用 setImageWithURLRequest 来加载图像,这也会给我一个 403 错误,但我编写了这段代码,使用 AFHTTPSessionManager 来尝试调试问题。)我能做什么AFNetworking 出错?

let request = NSMutableURLRequest()
request.HTTPMethod = "GET"
request.URL = coverPhotoUrl // A presigned url to an image on S3

// The operation succeeds if I uncomment the NSURLSession line
// and comment out the AFHTTPSessionManager line.
//NSURLSession.sharedSession().dataTaskWithRequest(request) {
AFHTTPSessionManager().dataTaskWithRequest(request) {
date, response, error in
if let error = error {
Log.error?.message("request failed: \(error.localizedDescription)")
} khác {
Log.debug?.message("request succeeded.")
}
}
.resume()

1 Câu trả lời

由于内容类型问题,AFNetworking 请求失败。在我将 S3 文件的内容类型从二进制/八位字节更改为图像/jpeg 后,setImageWithURL 起作用了。

让 S3 设置内容类型也很困难。为了防止其他人使用,S3 会忽略我的 PUT 请求中的内容类型,直到我指定内容长度。尽管实际文件要长得多,但在生成预签名 URL 时,我只是使用了虚拟长度 1。

关于swift - 使用 NSURLSession 时 GET 成功,但使用 AFHTTPSessionManager 时 GET 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39009149/

30 4 0
行者123
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com