我正嘗試在Azure應用服務中創建EasyAPI(從Azure移動服務遷移)。該消息在迅速使用以下命令iOS應用程序發送:如何閱讀Azure App Service中的請求正文?
let query: Dictionary<String, AnyObject> = ["name": theName]
let param: Dictionary<String, AnyObject> = ["collectionName": theCollectionName, "query": query]
AOAppDelegate.client!.invokeAPI("FMDataAPI", body: param, HTTPMethod: "POST", parameters: nil, headers: nil, completion: {(objects, httpResponse, error) in
if error == nil {
//Process response
} else {
print(error!.userInfo)
}
})
在API我有EasyAPI MyEasyAPI中下面的JavaScript代碼:
module.exports = {
"post": function (req, res, next) {
console.log("---------------------------------------")
console.log(req.body)
},
但身體撐不明確的。
有什麼建議嗎?
感謝,
GA
取出req.app.use線和參考bodyParser,爲移動應用服務將已經包含中間件爲您服務。如果您仍然遇到問題,那麼如何使用POST更新您的問題並使用當前代碼? –
嗨,感謝您的建議。我用我試過的新代碼編輯我的問題。我刪除了req.app.use行,並將post與req替換爲get。身體尚未定義。它是我需要使用的身體屬性嗎?參數來自req.query,但req.body似乎並不包含任何內容。非常感謝。 –
是的,req.body應該在服務器腳本中擁有主體內容。我懷疑客戶端不喜歡你傳遞給invokeAPI的嵌套字典。嘗試刪除查詢字典並使用所有參數定義param字典:'let param:Dictionary = [「collectionName」:theCollectionName,「name」:theName]' –