簡體   English   中英

TS/playwright - 如何使用 x-www-form-urlencoded 正文發布 api 請求?

[英]TS/playwright - how to post api request with x-www-form-urlencoded body?

我需要使用 x-www-form-urlencoded 正文創建劇作家 API 請求:來自 postman 的示例:工作 postman 請求示例

我試圖那樣做:

 async getNewApiAccesToken({request}) { const postResponse = await request.post("https://login.microsoftonline.com//token",{ ignoreHTTPSErrors: true, FormData: { 'client_id': 'xyz', 'client_secret': 'xyz', 'grant_type': 'client_credentials', 'scope': 'api://xyz' } }) console.log(await postResponse.json()); return postResponse;

但它不起作用:/你能告訴我如何在劇作家中提出這種要求嗎?

好的,我找到了解決方案!

 async getNewApiAccesToken({request}) { const formData = new URLSearchParams(); formData.append('grant_type', 'client_credentials'); formData.append('client_secret', '8xyz'); formData.append('client_id', 'xyz'); formData.append('scope', 'api://xyz/.default'); const postResponse = await request.post("https://login.microsoftonline.com/9xyz/v2.0/token",{ ignoreHTTPSErrors: true, headers:{ 'Content-Type': 'application/x-www-form-urlencoded' }, data: formData.toString() }) return postResponse; };

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM