vc http 请求
1.我现在在做毕业设计,我要做个前端IE播放器 显示HTML+SMIL脚本。现在问题是:我要向服务器发送http请求,服务器返回给我一个url。您觉得怎么实现,比较好?
2.我在网上找了段代码,一点击就程序就死了,这是怎么回事?我vc网络编程略懂一点,请cnzdgs大哥指点!
//---test2Dlg.h---#define MAXPATH 256class CTest2Dlg : public CDialog{public: BOOL HttpClient(void); void LogFile(char *p); afx_msg void OnButton1();private: char fname[MAXPATH];};//---test2Dlg.cpp---void CTest2Dlg::LogFile(char *p)//该函数把传递给它的字符串写到磁盘文件中{ FILE *fp=fopen(fname,"a+"); fprintf(fp,"%s\n",p); fclose(fp); }BOOL CTest2Dlg::HttpClient(){ WSADATA ws; SOCKET s; struct sockaddr_in addr; int iResult; long lResult; char strSubAddr[100], strBuffer[100]; lResult = WSAStartup(0x0101,&ws); s = socket(AF_INET,SOCK_STREAM,0); addr.sin_family = AF_INET; addr.sin_port = htons(80); addr.sin_addr.s_addr = inet_addr("168.160.224.185"); // 计算机世界日报 iResult=connect(s,(struct sockaddr *)&addr, sizeof(addr)); if(SOCKET_ERROR == iResult) { // 连接失败 WSACleanup(); return FALSE; } else { // 连接成功 strcpy(strSubAddr, "GET /99/tips/ \r\n"); strcpy(fname, "index.htm"); iResult = send(s, strSubAddr,strlen(strSubAddr),0); // 下载文件 do { strset(strBuffer,' '); iResult = recv(s,strBuffer,sizeof(strBuffer),0); LogFile(strBuffer); } while( iResult !=0 ); } WSACleanup(); return TRUE; }void CTest2Dlg::OnButton1() //单击 "Test" 按钮,"http://www.computerworld.com.cn/99/tips/"的index.htm文件将被下载到本地。 { HttpClient(); }