C ++卡萨布兰卡POST请求

时间:2015-03-30 01:24:32

标签: c++ json http minecraft casablanca

我正在开发定制的Minecraft发射器并遇到一些问题。我需要将带有一些JSON的POST请求发送到“https://authserver.mojang.com/”,然后检索返回的一些JSON。

但是,我在发送请求时遇到问题。每当我尝试发送HTTP请求时,它都会出错405 - 请求方法不正确。我不确定为什么这么说。身份验证要求详见:http://wiki.vg/Authentication。以下是我创建http_client的代码:

http_client client(L"https://authserver.mojang.com/");
http_request requester;
requester.set_body(obj2);
requester.set_method(methods::POST);
requester.headers().set_content_type(U("application/json"));

非常感谢任何帮助!

2 个答案:

答案 0 :(得分:1)

您发布的链接表示端点是/ authenticate,这让我相信网址应该是https://authserver.mojang.com/authenticate,而不是您在帖子中写的。试试吧。

答案 1 :(得分:-1)

以下请求正常运行并返回了一个访问令牌:

POST https://authserver.mojang.com/authenticate HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: application/json
Content-Length: 147
Host: authserver.mojang.com
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)

{
  "agent": {
    "name": "Minecraft",
    "version": 1
  },
  "username": "*******************",
  "password": "*********",
  "clientToken": ""
}