简体   繁体   中英

C++ Casablanca POST request

I'm working on a custom Minecraft launcher and having some issues. I need to send a POST request with some JSON in it to " https://authserver.mojang.com/ " and then retrieve some JSON that is returned.

However, I am having issues sending the request. Whenever I try to send the HTTP Request, it errors 405--the request method was not correct. I'm not sure why its saying that. The requirements for authentication are detailed at: http://wiki.vg/Authentication . Below is my code for creating the 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"));

Any help would be greatly appreciated!

The link you posted says the endpoint is /authenticate, which leads me to believe the URL should be https://authserver.mojang.com/authenticate , not the one you wrote in your post. Try that.

The following request works correctly and returned an access token:

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": ""
}

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