如何使用axios API和react native中的“GET”方法获得响应

uqxowvwt  于 2023-01-13  发布在  iOS
关注(0)|答案(1)|浏览(134)

下面是我的代码:

axios({
  method: "GET",
  url: "http://112.196.108.244:9002/api/survey/question/get-question/not-answered/?surveyId=",
  headers: {
    "content-type": "application/json",
    Authorization: `Bearer token-key`,
  },
  body: {
    id: "68367859",
    isMandatory: "false",
    paginationFilter: { limit: 10, offset: 0, order: "DESC" },
    filterInput: {
      locationIds: ["1", "4011403", "4012144"],
      categoryIds: [
        "twoSubCategories/7898496",
        "domains/7895290",
        "subCategories/7896491",
      ],
    },
  },
})
  .then((response) => {
    console.log("response", response);
  })
  .catch((error) => {
    console.log("error", error.response.data);
  });

这个代码给我错误:控制台中的错误是-

details: "uri=/api/survey/question/get-question/not-answered/"
message: "document key  is not valid."
status: 400
5lhxktic

5lhxktic1#

你要在body中传递id,这里有两个问题:

  1. GET请求不应使用正文作为请求的一部分。Check this answer
    1.您需要做的是将id(我假设是调查id)作为query parameter传递。
axios({
        method: 'GET',
        url: 'http://112.196.108.244:9002/api/survey/question/get-question/not-answered/',
        headers: {
            'content-type': 'application/json',
            Authorization: "Bearer token-key"
        },
        params: {
            surveyId: "68367859"
        }
    })

根据需要添加其他参数。

相关问题