带有主体信息的api GET请求引起的困惑和问题

时间:2019-03-19 17:08:30

标签: api get request bad-request

我已经阅读了一些资源,所以我进行了搜索,但不能感到困惑。

我从另一个人那里获得了我正在从事的项目的API。在他的文档中,他以邮递员为例,说明了我必须从前端进行的呼叫。不幸的是,一切似乎都很容易,每次我从应用程序调用API时,都会收到错误的请求。我相信这与我应该通过GET请求传递的身体信息有关。

对于GET请求,我应该将这样的内容放到正文中(或与请求一起发送)

{
"UserEmail" : "jbg@arosit.dk",

"FromDateUTC" : "2012-04-23T18:25:43.511Z"

}

我什至复制了邮递员的片段,将其放入函数中并尝试调用它。同样的错误。

邮递员代码段

var request = require("request");

var options = { method: 'GET',
  url: 'https://smtsmtsmt.azurewebsites.net/api/GetDeviceList',
  headers: 
   { 'Postman-Token': '8a2ed549-3a6e-481b-b77c-e37846cdc02c',
     'cache-control': 'no-cache',
     Authorization: 'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6Ik4tbEMwbi05REFMcXdodUhZbkhRNjNHZUNYYyIsImtpZCI6Ik4tbEMwbi05REFMcXdodUhZbkhRNjNHZUNYYyJ9.eyJhdWQiOiIzMDk5OGFhZC1iYzYwLTQxZDQtYTYwMi03ZDRjMTRkOTU2MjQiLCJpc3MiOiJodHRwczovL3N0cy53aW5kb3dzLm5ldC8zNWNhMjFlYi0yZjg1LTRiNDMtYjFlNy02YTlmNWE2YzBmZjYvIiwiaWF0IjoxNTUzMDEwMDQ0LCJuYmYiOjE1NTMwMTAwNDQsImV4cCI6MTU1MzAxMzk0NCwiYWlvIjoiQVVRQXUvOEtBQUFBRDRtR29pRjJiYmJqSDJpa2hnY0taMXZiZkVzd1dEMFcvMy9qakRLL0M4QUxFaXBlVHRPWTFBVEEwTmdGdE5ndFlhWWNqbThBcmFNVVplR3RuV2lJbGc9PSIsImFtciI6WyJwd2QiXSwiY19oYXNoIjoiYkZvVTdwc2ZwNHgzeDdtV0RkODF5QSIsImVtYWlsIjoidG9tYXNAM3BhcnQuY29tIiwiaWRwIjoiaHR0cHM6Ly9zdHMud2luZG93cy5uZXQvNjM5ZThkMmYtZmRhZi00NzBkLWIxMzYtOTU5NTMxNjkwNTdlLyIsImlwYWRkciI6IjE3OC4xNTcuMjQ5LjEzMCIsIm5hbWUiOiJUb23DocWhIEhhdmVybGEgM1BBUlQiLCJub25jZSI6IjRkNGY0YjFiMGY2YjQ5MmJiNzQ0ZTAzNDkxMGM5MmVlXzIwMTkwMzE5MTU1MDQ0Iiwib2lkIjoiOTk4MGM5ZjQtNzk5Yi00ODIwLTg0MmMtYTAyMGQwYTI4NDY2Iiwic3ViIjoiakhpWXdKbnU2bG1GRTl0MnlORzRheno1X2xKcmxJNEEzTU9abHZKdnZIUSIsInRpZCI6IjM1Y2EyMWViLTJmODUtNGI0My1iMWU3LTZhOWY1YTZjMGZmNiIsInVuaXF1ZV9uYW1lIjoidG9tYXNAM3BhcnQuY29tIiwidXRpIjoiRExiMEloc0NBRUs0alpTaUV1X1ZBQSIsInZlciI6IjEuMCJ9.Wd-JH5BYDg-U6naCE3GN6uVcn2O9ld5Tb0fJckB57lzofw5K1_fbguar-yRkFqhB5zWBKLrzdoHq3L-itkc8yeuQdtGShUEK7cxEL7cUCh0-PlZTeBqPxVgq0hfFy7FGOyVh_jYDrOqTLeNhJW_pYaggTmdte4dfb0ELgrdlRLFmQpr8HkbvTBZulYv7PvquJCEgd_2dirxQzLD4AszbnCOgjYEdmWbggA-pE5A05N1uC20EUzfu4EIcto8GGolVh6xzSvw8fpwKHikVr2Iq6oxZfyGi5BWq4OzL4__GYyI8DwVLX1TGufxM5bObEu7Y6picJmxHHDVCXvDkabgxIw' },
  body: '{"Usermail":"xy@xy.dk","FromDateUTC":"2012-04-23T18:25:43.511Z"}' };

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});

如果知识渊博的人可以建议我,如果API的制作方法不正确或使我感到困惑,我将不胜感激。

0 个答案:

没有答案