level 11
gameloftyou
楼主
winsock回帖函数:
void postTie(string fname,string tid,string reply)
{
SOCKET sock;
WSADATA wsadata;
ADDRINFOA *result,hints;
string header,content,host="tieba.baidu.com";
char szBuffer[1024];
int iError;
if(iError=WSAStartup(MAKEWORD(2,0),&wsadata))
{
cout<<"Startup error #"<<iError<<endl;
return;
}
sock = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
if(sock==INVALID_SOCKET)
{
cout<<"Socket creation error #"<<WSAGetLastError()<<endl;
WSACleanup();
return;
}
ZeroMemory(&hints,
sizeof(hints));
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = IPPROTO_TCP;
if((iError=getaddrinfo(host.c_str(),"80",&hints,&result))!=0)
{
cout<<"getaddrinfo error #"<<iError<<endl;
WSACleanup();
return;
}
connect(sock,result->ai_addr,
sizeof(SOCKADDR_IN));
content =
"kw="+MyUtil::UrlEncode(fname,"utf-8")+
2012年10月12日 14点10分
1
void postTie(string fname,string tid,string reply)
{
SOCKET sock;
WSADATA wsadata;
ADDRINFOA *result,hints;
string header,content,host="tieba.baidu.com";
char szBuffer[1024];
int iError;
if(iError=WSAStartup(MAKEWORD(2,0),&wsadata))
{
cout<<"Startup error #"<<iError<<endl;
return;
}
sock = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
if(sock==INVALID_SOCKET)
{
cout<<"Socket creation error #"<<WSAGetLastError()<<endl;
WSACleanup();
return;
}
ZeroMemory(&hints,
sizeof(hints));
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = IPPROTO_TCP;
if((iError=getaddrinfo(host.c_str(),"80",&hints,&result))!=0)
{
cout<<"getaddrinfo error #"<<iError<<endl;
WSACleanup();
return;
}
connect(sock,result->ai_addr,
sizeof(SOCKADDR_IN));
content =
"kw="+MyUtil::UrlEncode(fname,"utf-8")+