gpt4 book ai didi

ios - TRON 网址问题 swift

转载 作者:搜寻专家 更新时间:2023-11-01 06:17:00 24 4
gpt4 key购买 nike

我正在为 swift 使用 TRON 框架,但由于我的 url 而出现错误。这是代码:

let relatedTronUrl = TRON(baseURL: "https://api.themoviedb.org")

func fetchRelatedFeed(id: Int, completion: @escaping () -> ()){
let request: APIRequest<Related, JSONError> = relatedTronUrl.request("/3/tv/1402/similar?api_key=myAPIkey&language=en-US&page=1")

request.perform(withSuccess: { (related) in
print("Successfully fatched our json objects")
completion()
}) { (err) in
print("Failed to fetch json ",err)
}
}

如您所见,正确的 url 应该是:https://api.themoviedb.org/3/tv/1402/similar?api_key=myAPIkey&language=en-US&page=1但是当我运行我的应用程序时,我收到一个 JSON 错误:

Failed to fetch json  APIError<JSONError>(request: Optional(https://api.themoviedb.org/3/tv/1402/similar%3Fapi_key=myAPIkey&language=en-US&page=1), response: Optional(<NSHTTPURLResponse: 0x610000235f20> { URL: https://api.themoviedb.org/3/tv/1402/similar%3Fapi_key=myAPIkey&language=en-US&page=1 } { status code: 401, headers {
"Access-Control-Allow-Origin" = "*";
Connection = "keep-alive";
"Content-Length" = 86;
"Content-Type" = "application/json;charset=utf-8";
Date = "Wed, 01 Mar 2017 16:58:38 GMT";
Server = openresty;
Status = "401 Unauthorized";
"X-RateLimit-Limit" = 40;
"X-RateLimit-Remaining" = 39;
"X-RateLimit-Reset" = 1488387528;} }), data: Optional(86 bytes), error: Optional(Alamofire.AFError.responseValidationFailed(Alamofire.AFError.ResponseValidationFailureReason.unacceptableStatusCode(401))), errorModel: Optional(BookFinde.RelatedService.JSONError))

我认为问题是由于 TRON 的请求,因为正确的 url 是:https://api.themoviedb.org/3/tv/1402/similar?api_key=myAPIkey&language=en-US&page=1
但我得到的是:https://api.themoviedb.org/3/tv/1402/similar%3Fapi_key=myAPIkey&language=en-US&page=1
如您所见,不同之处在于 ? 转换为 %3F。我做错了什么?

最佳答案

这是我找到的解决方案:

let relatedTronUrl = TRON(baseURL: "https://api.themoviedb.org")

func fetchRelatedFeed(id: Int, completion: @escaping () -> ()){
let request: APIRequest<Related, JSONError> = relatedTronUrl.request("3/tv/\(id)/similar")

// I had to manually add the paramaters in this way
request.parameters = ["api_key":"myAPIkey","language":"en-US","page":"1"]

request.perform(withSuccess: { (related) in
print("Successfully fatched our json objects")
completion()
}) { (err) in
print("Failed to fetch json ",err)
}
}

关于ios - TRON 网址问题 swift ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42537980/

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