unity3d 如何正确编写对Unity服务器的请求

ve7v8dk2  于 2022-11-25  发布在  其他
关注(0)|答案(1)|浏览(229)

下午好!如何在Unity中正确地向服务器请求此API?我特别对Mint / burn感兴趣
https://docs.openvessel.io/integration/EZzgG67O9oXGl9CReheF/game-api/tokens
https://game-api.stage.openvessel.io/docs/ui/swagger-ui/index.html#/
此示例不起作用

IEnumerator Upload()
{
    MintTokin mintTokin = new MintTokin();
    mintTokin.to = walletAddress;
    mintTokin.amount = 10;
    var json = JsonUtility.ToJson(mintTokin);

    var request = new UnityWebRequest("https://game-api.openvessel.io//tokens/manage/com.stage.mv-game.mv-collection.mv-item/mint", "POST");
    byte[] bodyRaw = Encoding.UTF8.GetBytes(json);
    request.uploadHandler = (UploadHandler)new UploadHandlerRaw(bodyRaw);
    request.downloadHandler = (DownloadHandler)new DownloadHandlerBuffer();
    request.SetRequestHeader("X-Auth-Key", acesToken);
    request.SetRequestHeader("X-OpenVessel-Request-Id", "ab62663d-1645-4026-ba2d-d888b9634de9");
    yield return request.SendWebRequest();

    if (request.error != null)
    {
        Debug.Log("Erro: " + request.error);
        _statusText.text = request.error;
    }
    else
    {
        Debug.Log("All OK");
        Debug.Log("Status Code: " + request.downloadHandler.text);
    }
}
iyr7buue

iyr7buue1#

**强烈建议不要在任何游戏中使用它,因为它可能会导致无法控制地访问您的工作室钱包。应该通过Vessel控制面板进行Mint。**X-Auth-Key是与您的工作室ERC-20钱包关联的私钥。

以下步骤将对您有所帮助:

  • 仔细检查是否在血管 Jmeter 板中创建了{fqTn}
  • X-Auth-Key的值不应以“0x”前缀开头,如www.example.com中的示例所示https://game-api.stage.openvessel.io/docs/ui/swagger-ui/index.html#/03%20Tokens/mintToken
  • 调用mint的POST URL应该在临时环境中,并且后面没有双斜杠。
  • 另一个问题是X-OpenVessel-Request-Id;它应该是每个请求的唯一GUID,而不是硬编码的GUID。使用当前的代码片段,您将得到“给定的请求ID不是唯一的”错误。

相关问题