Mysql 如何处理通过url发送的问号?

Mysql 如何处理通过url发送的问号?,mysql,reactjs,post,axios,Mysql,Reactjs,Post,Axios,我正在使用axios向我的数据库发送一些字符串。我现在发送的东西是 1: Header -> the value can be anything such as "Who is Michael Scott?" 2: Body -> the value can be anything such as "Why do people quote Michael Scott a lot?" im使用的axios命令是: axios.post(`/post/create/${Header

我正在使用axios向我的数据库发送一些字符串。我现在发送的东西是

1: Header -> the value can be anything such as "Who is Michael Scott?"
2: Body -> the value can be anything such as "Why do people quote Michael Scott a lot?"
im使用的axios命令是:

  axios.post(`/post/create/${Header}/${Body}`).then(result => {
    alert("Your post has been added!")
    console.log("Posted")
  }).catch(function (error) {
      // Output error
      console.log(error);
  });
url(地址栏)中的输出为:

因为这个问号,我得到了404分。我的问题是,如何处理作为url参数传递的字符串中的问号


如果有帮助,我将使用React.js、Axios和Mysql。

您需要对它们进行URL编码

在将它们的值传递给axios之前,请确保运行
encodeURIComponent(myString)

也许是这样:

axios.post(`/post/create/${encodeURIComponent(Header)}/${encodeURIComponent(Body)}`).then(result => {...}

您需要对它们进行URL编码

在将它们的值传递给axios之前,请确保运行
encodeURIComponent(myString)

也许是这样:

axios.post(`/post/create/${encodeURIComponent(Header)}/${encodeURIComponent(Body)}`).then(result => {...}

我认为如果您使用这个url:
/post/create/${Header}/${Body}
不是最佳实践。 若你们使用post方法,我建议你们把你们的数据传递给身体

axios.post(`/post/create/`, {header: Header, body:Body}).then(result => {
    alert("Your post has been added!")
    console.log("Posted")
}).catch(function (error) {
    // Output error
    console.log(error);
});

我认为如果您使用这个url:
/post/create/${Header}/${Body}
不是最佳实践。 若你们使用post方法,我建议你们把你们的数据传递给身体

axios.post(`/post/create/`, {header: Header, body:Body}).then(result => {
    alert("Your post has been added!")
    console.log("Posted")
}).catch(function (error) {
    // Output error
    console.log(error);
});

您可以将数据作为查询参数传递和检索/post/create?header='your header'&body='your body'您也可以将数据作为查询参数传递和检索/post/create?header='your header'&body='your body'谢谢!!我很惊讶我在谷歌上搜索了这么多,却一次也没有在任何地方看到encodeURIComponent()!感谢您的快速和简短的答复布鲁诺!非常感谢。我很惊讶我在谷歌上搜索了这么多,却一次也没有在任何地方看到encodeURIComponent()!感谢您的快速和简短的答复布鲁诺!