简体   繁体   English

如何使用 axios 在 Localhost 中通过 Get 将参数传递到 Url

[英]How I pass Parameters into Url with Get in Localhost with axios

I want to consume my api.我想使用我的 api。 it is in go lang.它在 go lang 中。 i use axios in front (react) for consume it我在前面使用 axios(反应)来消耗它

my route:我的路线:

localhost:1323/profile/email/:email/password/:password本地主机:1323/profile/email/:email/password/:password

i don't know how i can pass the email and password in axios request with get.我不知道如何使用 get 传递 axios 请求中的电子邮件和密码。

my code:我的代码:

import axios from 'axios'

    export async function validLogin(email, password) { 
      const valid = await axios.get('localhost:1323/profile/email/'+ email + '/password/'+ password).then((response) => {
        return response;
      });
      return valid
    }

I tried to use http://localhost instead localhost pure, but don't work too.我尝试使用 http://localhost 而不是 localhost pure,但也不起作用。

  • You need the scheme.你需要这个方案。
  • You need to encode special characters (like @ !) before shoving them into the URL.您需要在将特殊字符(如@ !)插入 URL 之前对其进行编码
  • Template strings save on concatenation模板字符串保存在连接上

Such:这样的:

const url = `http://localhost:1323/profile/email/${encodeURIComponent(email)}/password/${encodeURIComponent(password)}`

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

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