gpt4 book ai didi

swift - :url loads url content of a truncated URL 的内容

转载 作者:行者123 更新时间:2023-11-28 07:44:58 25 4
gpt4 key购买 nike

当我使用 contentsof:url 时,它会在检索内容之前截断 url,从而导致 html 内容与 WKWebView 中显示的内容不同。

例如

contents = try String(contentsOf: https://www.amazon.com/gp/aw/d/B00BECJ4R8/ref=mp_s_a_1_1?ie=UTF8&qid=1531620716&sr=8-1-spons&pi=AC_SX236_SY340_QL65&keywords=cole+haan&psc=1)

返回此页面的内容:https://www.amazon.com/gp/aw/d/B00BECJ4R8/

为什么会这样?是否有其他方法允许您读取实际 URL 的内容而不是截断的 URL?

任何建议,如果非常感谢。

谢谢。

最佳答案

您不应该使用 String(contentsOf:) 来加载网站。您应该为此工作使用 URL 加载系统,然后将该对象传递回 viewDidLoad()

中的 webView.load(_:) 方法
 let urlString = "https://www.amazon.com/dp/B00BECJ4R8/?tag=stackoverflow17-20"
// URL construct may fail in case of the String not being a properly formatted URL, so unwrap it.
if let url = URL(string: urlString) {
// Create a URLRequest instance with the new url.
let request = URLRequest(url: url)
// Load the request.
webView.load(request)
}

关于swift - :url loads url content of a truncated URL 的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51344816/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com