简体   繁体   English

如何使用/阅读此 curl api 并添加数据限制,POST 方法

[英]how to use/read this curl api and add limit for data, POST method

so i got this api from my partner and i never use this kind of api format and i asked to put limit parameter so it will only recieve certain data limit.所以我从我的伙伴那里得到了这个 api,我从不使用这种 api 格式,我要求输入限制参数,所以它只会收到一定的数据限制。 But i don't understand where to put this --data .但我不明白把这个--data放在哪里。 if the method is GET it's fine i just need to add ?limit=10&page=1 in the url but for the POST method how?如果方法是 GET 很好,我只需要在 url 中添加?limit=10&page=1但对于 POST 方法如何? i usually put body:{"limit":10} for POST but now it doesn't work我通常将body:{"limit":10}用于 POST 但现在它不起作用

  curl --request POST \
  --url https://base-url.com/api/v2/order/all/79025884 \
  --header 'Content-Type: application/json' \
  --cookie 'connect.sid=s%253ArO7T68J_dUxbwAoogHU.ezS9SwNk1gb8AgJxOUqjzoJoza9ETpE7t1TDugussQY; token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJwaG9uZU51bWJlciI6IjA4MTExNzA5MjIxIiwidXNlcm5hbWUiOiJGbG8iLCJpYXQiOjE2NjE2NDI0NjcsImV4cCI62N30.8hyXmK3H0N9Iccedv9XSs6_rbtmToS8B0woxWNj9IXM' \
  --data '{
    "limit":10,
    "page":1
}'

my fetch api code我获取 api 代码

  const url = APIConfig.SERVER.ORDER + "/all/" + userID;
    fetch(url, {
      method: "POST",
      headers: { "content-type": "application/JSON" },
    })
      .then((response) => response.json())
      .then((data) => {
        setOrderList(data.data);
      })
      .catch((error) => {
        console.error("Error:", error);
      });

You can do like:你可以这样做:

const url = APIConfig.SERVER.ORDER + "/all/" + userID;
    fetch(url, {
      method: "POST",
      headers: { "content-type": "application/JSON" },
      body: JSON.stringify({
                limit:10,
                  page:1
             })
    })
      .then((response) => response.json())
      .then((data) => {
        setOrderList(data.data);
      })
      .catch((error) => {
        console.error("Error:", error);
      });

Hope it helps, feel free for doubts希望对你有帮助,有疑问欢迎交流

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM