HTTP POST/GET [Solved]

Posts 1–10 of 10 · Page 1 of 1
HTTP POST/GET [Solved]
I need to connect to a website and recv the response after i post the data.
https://login.minecraft.net/?user=us...ord&version=13
is the website that i need to navigate to via c++.
i can connect to the site but having trouble with the syntax. I always recv() a BAD_REQUEST 400.
sprintf(postreq, "POST user=%s&password=%s&version=13 HTTP/1.1\r\n", username, password);
sprintf(postreq, "%sHost: login.minecraft.net\r\n", postreq);
sprintf(postreq, "%sContent-Type: application/x-www-form-urlencoded\r\n\r\n", postreq);
I should recive 4 values, but i recive the bad_request. Any help?
bump!ffffffffffffffff
It's not working because your POST request is invalid.

A general and correct POST request looks like the following:

Code:
	POST <page> HTTP/1.1
	Host: <host>
	User-Agent: <useragent>
        Content-Type: <type>
	Content-Length: <len>

        <params>
If you aren't creating a commercial server or client, and a simple post request is all you need, you don't need to read the entire manual as only 15% of it will likely concearn your situation.

When I was writing a webbased server for prototyping purposes, I used the below as a reference (a much more practical read for a simple client or server)
HTTP Made Really Easy

Be prepared to work with a text-parsing or regex engine.
@radnomguywfq3, are you tracking the progress of the PIPA and SOPA bills?

I read you signature and I saw something similar. It's just outrageous that they (1) let people completely ignorant of the features and the technology behind the Internet judge over how it should be used and (2) that American corporations could damage or control an international treasure of information and innovation. It's just too horrible and stupid for words. The Internet would change from a medium of free-speech and freedom to just another channel for big companies and politicians to spam us to death with their products and propaganda, we must not allow this to happen.
Quote Originally Posted by .::SCHiM::. View Post
@Jetamay, are you tracking the progress of the PIPA and SOPA bills?

I read you signature and I saw something similar. It's just outrageous that they (1) let people completely ignorant of the features and the technology behind the Internet judge over how it should be used and (2) that American corporations could damage or control an international treasure of information and innovation. It's just too horrible and stupid for words. The Internet would change from a medium of free-speech and freedom to just another channel for big companies and politicians to spam us to death with their products and propaganda, we must not allow this to happen.
I agree, AFAIK there are more than enough signatures to stop the bill, however I'm not absolutely sure; regardless I am keeping it in my signature until the website expires. Though I can't sign it myself as I am from Canada - but Canada is always just a few steps behind the USA. I think that preventing it the USA will help discourage it elsewhere. Anyway, I agree, anyone passing this bill uses a computer to access their emails and thats it - totally oblivious & ignorant to the technology. Its disgusting how these fools actually have the power to even propose such a bill.
perhaps this will help..
Code:
To log the player in, the official launcher sends an HTTPS POST request to:
https://login.minecraft.net
with the postdata:
 user=<username>&password=<password>&version=<launcher version>
and a "application/x-www-form-urlencoded" Content-Type header.
The current launcher version is 12, sending a value lower than this will cause the server to return "Old Version", however you can send any large number and it will return as expected. If the login succeeded, it will return 4 ':' delimited values.
 1281688214000:deprecated:TkTech:8204407531530365141:
current version of the game files (not the launcher itself). This is a unix timestamp which the launcher compares to the ~/.minecraft/bin/version file.
Previously contained a download ticket for requesting new versions of minecraft.jar from the server. Now contains only "deprecated".
case-correct username.
sessionId - a unique ID for your current session.
this is what im trying to do. my function:
Code:
int login(const char username[16], const char password[32])
{
	DWORD ip;
	conout("logging on...");
	hostent* host = gethostbyname("login.minecraft.net");
	if(host == NULL)
	{
		conout("bad host");
		return WSAGetLastError();
	}
	ip = *(unsigned long*) host->h_addr;
	
	SOCKET loginsock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);

	sockaddr_in login;
	login.sin_family = AF_INET;
	login.sin_port = htons(80);
	login.sin_addr.s_addr = ip;
	memset(login.sin_zero, '\0', sizeof(login.sin_zero));

	
	char postreq[8192];
	char parameters[100];
	sprintf(parameters, "user=%s&password=%s&version=99", username, password);
	ZeroMemory(&postreq, sizeof(postreq));
	sprintf(postreq, "POST %s HTTP/1.1\r\n", parameters;);
	sprintf(postreq, "%sHost: login.minecraft.net\r\n", postreq);
	sprintf(postreq, "%sContent-Type: application/x-www-form-urlencoded\r\n", postreq);
	sprintf(postreq, "%sContent-Language: en-US\r\n", postreq);
	sprintf(postreq, "%sContent-Length: %i\r\n", postreq, strlen(parameters));
	sprintf(postreq, "%s\r\n", postreq);

	if(connect(loginsock, (sockaddr*)&login, sizeof(login)) == -1)
	{
		conout("error logging in");
		closesocket(loginsock);
		WSACleanup();
		return WSAGetLastError();
	}
	
	if(send(loginsock, postreq, strlen(postreq), 0) == -1)
	{
		conout("error sending data");
		WSACleanup();
		closesocket(loginsock);
		return WSAGetLastError();
	}
	
	conout("login info sent");
	char buf[8192];
	unsigned size = recv(loginsock, buf, sizeof(buf), 0);
	printpacket(buf, size);
	return 0;
}
/solved, close please
Marked Solved.
Posts 1–10 of 10 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us