如何从URL提取响应,然后将所述响应放入JSON

问题描述 投票:0回答:1

我需要向https://authserver.mojang.com/authenticate发送请求

并获得响应

    "accessToken": "valid accessToken",
    "clientToken": "client identifier",  

    "selectedProfile": {                 
        "id": "profile identifier",      
        "name": "player name"
    },
    "requestUser": true 
}```
but I dont know how to ask the server for the out put.
What I need to input is 
```{"agent": {"name": "Minecraft", "version": 1},
"username": "-email here-",
"password": "-pass here-"}
That is the data needed to get the token but I can't seem to get the code to ask the server for the token data and than receive it and put it into a JSON.
javascript authentication minecraft
1个回答
0
投票
const postData = async _ => {
  const response = await fetch(url, {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
      "agent": { "name": "Minecraft", "version": 1 },
      "username": "-email here-",
      "password": "-pass here-"
    })
  })

  console.log(response)
}
© www.soinside.com 2019 - 2024. All rights reserved.