大家帮个忙 大家帮个忙,给我一个最简单的C/S例子,界面最好用MFC,但接口部分用API的WINSOCK1/WINSOCK2发到我的E-MAIL :[email protected] 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 //Get html page by SDK socket#define host_name "www.csdn.net"#define winsock_version 0x0101void main(){ SOCKADDR_IN saServer; LPHOSTENT lphostent; WSADATA wsadata; SOCKET hsocket; int nRet; char hostname[100] ; wsprintf(hostname,"GET /expert/topic/378/378382.shtm HTTP/1.0 %c%c",10,10); printf("%s",hostname); char dest[1000]; if(WSAStartup(winsock_version,&wsadata)) printf("can't open"); lphostent=gethostbyname(host_name); if(lphostent==NULL) printf("lphostent is null"); hsocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); saServer.sin_family = AF_INET; // Use def. now, need to handle general case saServer.sin_port = htons(80); saServer.sin_addr = *((LPIN_ADDR)*lphostent->h_addr_list); nRet = connect(hsocket, (LPSOCKADDR)&saServer, sizeof(SOCKADDR_IN)); if (nRet == SOCKET_ERROR) { printf("can't connect"); closesocket(hsocket); return; } else printf("connected with %s\n",host_name); nRet = send(hsocket, hostname, strlen(hostname), 0); if (nRet == SOCKET_ERROR) { printf("send() failed"); closesocket(hsocket); } else printf("send() OK\n"); nRet=1; while(nRet>0) { nRet=recv(hsocket,(LPSTR)dest,sizeof(dest),0); if(nRet>0) dest[nRet]=0; else dest[0]=0; printf("\nReceived bytes:%d\n",nRet); printf("Result:\n%s",dest); } }/////////////////////////////////////////////////////////////////////////////SDK post///////////////////////////////////////////////////////////////////////////#include "stdafx.h"#include "winsock.h"#pragma comment(lib,"ws2_32.lib")#define winsock_version 0x0101void main(){ //I create C:\Inetpub\wwwroot\test\test.asp ,start the web service //start my program, the result is OK. //If it works,it is written by masterz,otherwise I don't know who write it. SOCKADDR_IN saServer; LPHOSTENT lphostent; WSADATA wsadata; SOCKET hsocket; int nRet; const char* host_name="127.0.0.1"; char* req="POST /test/test.asp HTTP/1.0\r\n" "From: local\r\n" "User-Agent: post_test/1.0\r\n" "Content-Type: application/x-www-form-urlencoded\r\n" "Content-Length: 20\r\n\r\n" "type=12345&name=aaaa"; if(WSAStartup(winsock_version,&wsadata)) printf("can't initial socket"); lphostent=gethostbyname(host_name); if(lphostent==NULL) printf("lphostent is null"); hsocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); saServer.sin_family = AF_INET; // Use def. now, need to handle general case saServer.sin_port = htons(80); saServer.sin_addr = *((LPIN_ADDR)*lphostent->h_addr_list); nRet = connect(hsocket, (LPSOCKADDR)&saServer, sizeof(SOCKADDR_IN)); if (nRet == SOCKET_ERROR) { printf("can't connect"); closesocket(hsocket); return; } else printf("connected with %s\n",host_name); nRet = send(hsocket, req, strlen(req), 0); if (nRet == SOCKET_ERROR) { printf("send() failed"); closesocket(hsocket); } else printf("send() OK\n"); char dest[1000]; nRet=1; while(nRet>0) { nRet=recv(hsocket,(LPSTR)dest,sizeof(dest),0); if(nRet>0) dest[nRet]=0; else dest[0]=0; printf("\nReceived bytes:%d\n",nRet); printf("Result:\n%s",dest); } } vcp4.51.net/VC/Net.htm上有一个例子 vc++MFC Win32 开机第一条指令是如何取到和执行的? ADO远程连接SQL SERVER 2005数据库不通,哪位高手帮忙看看!!!! 求教:自动色彩(auto color)的算法 如何访问一个类的保护成员???? 多个相同的控件可否共享同一事件? 散粉 handle Windows中的定时器消息的精度问题 版主啊~!!我的专家分怎么少了这么多啊?这已不是第一次啦!!! 求读写“TIF”图像格式的源代码 请问为何把用动态DLL编译改为使用静态MFC DLL编译会有这样的错误
#define host_name "www.csdn.net"
#define winsock_version 0x0101
void main()
{
SOCKADDR_IN saServer;
LPHOSTENT lphostent;
WSADATA wsadata;
SOCKET hsocket;
int nRet;
char hostname[100] ;
wsprintf(hostname,"GET /expert/topic/378/378382.shtm HTTP/1.0 %c%c",10,10);
printf("%s",hostname);
char dest[1000];
if(WSAStartup(winsock_version,&wsadata))
printf("can't open");
lphostent=gethostbyname(host_name);
if(lphostent==NULL)
printf("lphostent is null");
hsocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
saServer.sin_family = AF_INET;
// Use def. now, need to handle general case
saServer.sin_port = htons(80);
saServer.sin_addr = *((LPIN_ADDR)*lphostent->h_addr_list);
nRet = connect(hsocket, (LPSOCKADDR)&saServer, sizeof(SOCKADDR_IN));
if (nRet == SOCKET_ERROR)
{
printf("can't connect");
closesocket(hsocket);
return;
}
else
printf("connected with %s\n",host_name);
nRet = send(hsocket, hostname, strlen(hostname), 0);
if (nRet == SOCKET_ERROR)
{
printf("send() failed");
closesocket(hsocket);
}
else
printf("send() OK\n");
nRet=1;
while(nRet>0)
{
nRet=recv(hsocket,(LPSTR)dest,sizeof(dest),0);
if(nRet>0)
dest[nRet]=0;
else
dest[0]=0;
printf("\nReceived bytes:%d\n",nRet);
printf("Result:\n%s",dest);
}
}///////////////////////////////////////////////////////////////////////////
//SDK post
///////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "winsock.h"
#pragma comment(lib,"ws2_32.lib")
#define winsock_version 0x0101
void main()
{
//I create C:\Inetpub\wwwroot\test\test.asp ,start the web service
//start my program, the result is OK.
//If it works,it is written by masterz,otherwise I don't know who write it.
SOCKADDR_IN saServer;
LPHOSTENT lphostent;
WSADATA wsadata;
SOCKET hsocket;
int nRet;
const char* host_name="127.0.0.1";
char* req="POST /test/test.asp HTTP/1.0\r\n"
"From: local\r\n"
"User-Agent: post_test/1.0\r\n"
"Content-Type: application/x-www-form-urlencoded\r\n"
"Content-Length: 20\r\n\r\n"
"type=12345&name=aaaa";
if(WSAStartup(winsock_version,&wsadata))
printf("can't initial socket");
lphostent=gethostbyname(host_name);
if(lphostent==NULL)
printf("lphostent is null");
hsocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
saServer.sin_family = AF_INET;
// Use def. now, need to handle general case
saServer.sin_port = htons(80);
saServer.sin_addr = *((LPIN_ADDR)*lphostent->h_addr_list);
nRet = connect(hsocket, (LPSOCKADDR)&saServer, sizeof(SOCKADDR_IN));
if (nRet == SOCKET_ERROR)
{
printf("can't connect");
closesocket(hsocket);
return;
}
else
printf("connected with %s\n",host_name);
nRet = send(hsocket, req, strlen(req), 0);
if (nRet == SOCKET_ERROR)
{
printf("send() failed");
closesocket(hsocket);
}
else
printf("send() OK\n");
char dest[1000];
nRet=1;
while(nRet>0)
{
nRet=recv(hsocket,(LPSTR)dest,sizeof(dest),0);
if(nRet>0)
dest[nRet]=0;
else
dest[0]=0;
printf("\nReceived bytes:%d\n",nRet);
printf("Result:\n%s",dest);
}
}
上有一个例子