【发布时间】:2014-01-27 10:55:01
【问题描述】:
现在我开始研究插座。但它不能用我的手正常工作。我有很酷的登录方法:
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)
请帮忙,谢谢。
【问题讨论】: