简体   繁体   中英

How I pass Parameters into Url with Get in Localhost with axios

I want to consume my api. it is in go lang. i use axios in front (react) for consume it

my route:

localhost:1323/profile/email/:email/password/:password

i don't know how i can pass the email and password in axios request with get.

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.

  • You need the scheme.
  • You need to encode special characters (like @ !) before shoving them into the URL.
  • Template strings save on concatenation

Such:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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