的編碼塊Alamofire我有一樣網址:如何從查詢參數
https://baseUrl/v2/orders/bookings?ourl=411093%7cMdTal8dUR6xpXXpzOiGgD1hRFnOyAHeo0Om9HeuB4Mk%3d
我用Alamofire這樣的:我在創建自定義枚舉類來獲得URLRequestConvertible
參數和參數我傳遞到alamofire
Alamofire.request(HotelBookingConfirmationRouter.get(orderUrl))
.responseObject{(response: DataResponse<HotelBookingConfirmation>) in }
enum HotelBookingConfirmationRouter: URLRequestConvertible {
case get(String)
public func asURLRequest() throws -> URLRequest {
var method: HTTPMethod {
return .get
}
let url: URL = {
let url = URL(string: RBHWebServiceConfiguration.endpoint())!
return url.appendingPathComponent(HotelAPI.bookingConfirmation)
}()
let params: ([String: String]) = {
switch self {
case .get(let ticketUrl):
var dict = ["" : ""]
dict = [ "ourl" : ticketUrl]
return dict
}
}()
var urlRequest = URLRequest(url: url)
urlRequest.setValue("MOBILE_APP", forHTTPHeaderField: "channel_name")
let encoding = URLEncoding.queryString
var encodedRequest = try! encoding.encode(urlRequest, with: params)
encodedRequest.httpMethod = method.rawValue
encodedRequest.timeoutInterval = 30
return encodedRequest
}
}
登錄請求,收到:
https://baseUrl/v2/orders/bookings?ourl= 411093%2547cMdTal8dUR6xpXXpzOiGgD1hRFnOyAHeo0Om9HeuB4Mk%3d
查詢字符串編碼,即,「2547」,而不是「7CM」
但是,我需要保持與相同參數的任何人都可以請幫我解決這個問題