通过套接字接收GET请求

我怎样才能通过套接字接收GET请求? 例如,我正在浏览器中写入:

127.0.0.1:41233/?data=mymessage

我希望我的应用程序能够接收“mymessage”。 我写了这段代码,但recv()返回WSAENOTCONN错误,我不知道如何解决它。

int main() { WSADATA socketData; SOCKET portListener; struct sockaddr_in saInfo = {0}; if ( WSAStartup( MAKEWORD(1, 1), &socketData ) != 0) { printf( "WSAStartup() error!" ); return 0; } portListener = socket( AF_INET, SOCK_STREAM, 0 ); if ( portListener == INVALID_SOCKET ) { printf( "socket() error!" ); } else { saInfo.sin_family = AF_INET; saInfo.sin_port = htons(41233); saInfo.sin_addr.S_un.S_addr = inet_addr( "127.0.0.1" ); if ( bind( portListener, ( sockaddr * ) &saInfo, sizeof(saInfo)) == SOCKET_ERROR ) { printf( "bind() error!\n" ); closesocket( portListener ); return 0; } if ( listen( portListener, SOMAXCONN ) == SOCKET_ERROR ) { printf( "listen() error!\n" ); closesocket( portListener ); return 0; } if ( accept( portListener, NULL, NULL ) == INVALID_SOCKET ) { printf( "accept() error!\n" ); closesocket( portListener ); return 0; } char buf[128]; int rcvCount; rcvCount = recv( portListener, buf, 128, 0 ); printf( "Error: %d\n", WSAGetLastError() ); if ( rcvCount > 0 ) { printf( "%s\n", buf ); } closesocket( portListener ); } WSACleanup(); return 0; } 

Solutions Collecting From Web of "通过套接字接收GET请求"