現在我開始研究套接字了。但是我的雙手無法正常工作。我有很酷的登錄方法:POST Winsock麻煩
int LogIn(const string &name, const string &password)
{
char Buffer[1024];
string data = "login=" + name + "&password=" + password;
sprintf(Buffer, "POST /Test/login_cl.php HTTP/1.1\r
"\nContent-Length: %d\r"
"\nConnection: Keep-Alive\r"
"\nAccept-Encoding: gzip\r"
"\nAccept-Language: ru-RU,en,*\r"
"\nUser-Agent: Mozilla/5.0\r"
"\nHost: 127.0.0.1\r"
"\nContent-Type: application/x-www-form-urlencoded\r\n\r\n"
"login=%s&"
"password=%s&", data.length(), name.c_str(), password.c_str());
int BytesSent = send(MySocket, Buffer, sizeof(Buffer), 0);
string test;
char ans;
while (recv(MySocket, &ans, 1, 0))
test.push_back(ans);
cout << test << endl;
return 0;
}
問題是我只能調用一次這個方法。其他來電或註銷方法調用不工作,例如:
int result = LogIn(logn, paswd);
int result = LogIn(logn, paswd);
不工作,我得到的答案只有一個(第二個是空的和recv將返回-1)
請幫忙,謝謝。
謝謝,現在試圖使用winhttp –