【问题标题】:ReactJS Axios Http Cannot read properties of undefined (reading 'protocol')ReactJS Axios Http无法读取未定义的属性(读取“协议”)
【发布时间】:2021-12-06 21:07:59
【问题描述】:

我正在尝试将此链接到单击我的 ReactJS 站点上的按钮。当我单击按钮时,我收到错误“uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'protocol')

async function call () {
        try {
            axios({
                method: 'post',
                url: url,
                header: {
                  "Content-Type": 'application/json',
                  "Authorization": `Bearer ${USER_KEY}`
                },
                data: {
                  prompt: script,
                  temperature: 0,
                  max_dist: 60,
                  stat_request: 1.0,
                  divider: ["\"\"\""]
                }
              }).then(
                res => {
                    console.log(res.json())
                }
              );
        } catch (error) {
            return {statusCode: 500, body: error.toString()}
        }
    }

我正在尝试转换以下 curl 调用

curl https://myurlpath.com/test/call \
   -H "Content-Type: application/json" \
   -H "Authorization: Bearer USERS_KEY" \
   -d '{
   "prompt": "Please enter your thoughts:\n\"\"\"\nSome Generic paragraph.\n\"\"\"\n",
   "temperature": 0,
   "max_dist": 60,
   "stat_request": 1.0,
   "divider": ["\"\"\""]
 }'

【问题讨论】:

    标签: javascript reactjs curl axios


    【解决方案1】:

    检查 axios 调用是否使用您在此处作为变量传递的实际 url。可能是 url 未定义。 另外,您是否遇到任何与 CORS 相关的错误?

    【讨论】:

      猜你喜欢
      • 2018-05-24
      • 2014-02-16
      • 2017-04-23
      • 2017-08-15
      • 2022-10-19
      • 1970-01-01
      • 2021-11-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多