![](/img/trans.png)
[英]Postman returns 415 when trying to do a POST using form-data, but the same request with JSON works fine
[英]Using postman to test POST request, how do I access the form-data inside the request?
我已經搜索了幾個小時,我需要幫助。 我不認為我使用的是正確的單詞。 無論如何,我正在使用Claudia.JS為我的AWS Lambda函數設置POST請求。 這是該函數的基礎:
api.post('/leads', function (request) {
console.log(request);
return request;
});
當我使用郵差測試發布請求時,我返回了請求對象。 真棒。 然后,我嘗試通過表單數據。 我將密鑰設置為“用戶名”,並將值設置為“這是用戶名”。 這是request.body是:
"body": "---------------------------
-019178618034620042564575\r\nContent-Disposition: form-data;
name=\"username\"\r\n\r\nthis is the username\r\n----------------------
------019178618034620042564575--\r\n",`
我以為我可以返回request.body.username ...來鍵入username的值...但是我丟失了一些東西。
如何訪問請求中的表單數據?
更新:好的。 網站正在接收表單數據,發出過帳請求...此功能正在接收過帳請求嗎? 仍然-在郵遞員中...如果我要在其中放入自己的JSON ...為什么我不能像... request.body.username那樣訪問request.body?
您應該嘗試console.log(request.data)
來查看您的請求對象,即。 就我自己而言,我可以看到請求正文的內容。
請訪問https://www.getpostman.com/docs/postman/scripts/postman_sandbox以查看有關您請求的所有相關信息。
我通過查看郵遞員中設置的標題解決了這個問題。 它被設置為表單數據,而不是應用程序/ JSON。 現在所有肉汁。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.