簡體   English   中英

通過 Postman 發送 API 請求?

[英]Sending API request via Postman?

我正在使用我以前從未做過的 API 申請工作。 我不知道我在做什么,Postman 給我一個錯誤消息:ReferenceError: Request is not defined。 注意:現在我正在使用測試腳本,直到我准備好實際發送它。

這是我的代碼:

const url = 'https://url.org';

let info = {
  applicant: 'John Doe',
    "users":[
     {
        "first_name":"John",
        "last_name": "Doe",

        "company_name": "Company",

        "company_full_address": "Address Here", 

       "website": "Website",

       "phone": "5555555555"
    } 
  ]
}

let success = {
  "success" : "True",
  "message" : "Thank you {John Doe} for your application"
}

var request = new Request(url, {
    method: 'POST',
    body: info,
    headers:{ 'Content-type': 'application/json'}
});

fetch(request)
.then(function() {

let formatData = info.users;
var array = [];
  
    for (var i = 0; i < formatData.length; i++){
      array.push([i,formatData[i]])
      console.log(array);
    }

})

.then(function() {
 console.log(success);
})

任何幫助表示贊賞。 謝謝。

Postman 是一個模擬您的代碼在做什么的應用程序。在全球范圍內,它是一個 REST API 應用程序模擬器。 你要做的是,復制信息的內容。 將它放在postman中的body標簽中並將其設置為JSON,將“const url”的內容放在postman Z5272114E4211E8A0D字段中並按發送按鈕。

更多信息在這里: https://learning.postman.com/docs/publishing-your-api/documenting-your-api/

暫無
暫無

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

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