0
我試圖做一個Firebase雲計算函數調用,它傳遞一個參數,該參數是特定url的字符串表示形式。在大多數情況下,我有我的雲功能獲取var somePath = req.query.somePath;
的參數,並執行我想要的那些變量的所有邏輯。但是,url包含?
和&
符號,我認爲可能會讓Alamofire感到困惑,認爲&
之後的數據是自己傳遞的參數。Cloud Function HTTP請求參數被拆分爲「&」
MY未遂
let somePath = "https://www.somewebsite.com/someSubpath?firstID=firstValue&someID=someValue"
let url = "https://us-central1-[myProjectName].cloudfunctions.net/myfunction?somePath=" + somePath + "&someData=" + someData
Alamofire.request(url, method: .post, parameters: nil, encoding: JSONEncoding.default, headers: nil).responseJSON {
response in
print("original URL request")
print(response.request as Any) // original URL request
print("URL response")
print(response.response as Any) // URL response
print(response.response?.statusCode ?? "response.response?.statusCode is nil")
}
我猜測在somePath
的&
導致someID
被視爲另一個參數,所以我 雲功能,認爲somePath
=
https://www.somewebsite.com/someSubpath?firstID=firstValue
但應該=
https://www.somewebsite.com/someSubpath?firstID=firstValue&someID=someValue
有了這個猜測一點,我又試圖 發生變化:
Alamofire.request(url, method: .post, parameters: nil, encoding: JSONEncoding.default, headers: nil).responseJSON {
要:
Alamofire.request(url, method: .post, parameters: ["somePath": somePath ?? ""], encoding: JSONEncoding.default, headers: nil).responseJSON {
但這只是導致了另一個錯誤somePath
沒有被作爲參數傳遞。
有沒有人知道我怎樣才能防止somePath
被分裂,儘管它有?
和&
在裏面?
工作就像一個魅力!這很有道理。非常感謝。 – Rbar