加载后如何从网络获取日期 [英] How to get the date from web after loading
问题描述
加载后如何获取日期表单网站.
我使用了套接字,但是找不到正确的日期.
我的代码如下:
1,err = WSAStartup(0x0101,& WsaData);
2,袜子=插座(AF_INET,SOCK_STREAM,0);
3,连接(袜子,(LPSOCKADDR)& sin,sizeof(SOCKADDR_IN))
4,发送(袜子,protocolHead,protocolHead.GetLength(),0)
在这一步中,我不知道protocolHead的值,而是这样设置的
CString protocolHead ="GET/hsicpweb/Login.jsp HTTP/1.1 \ r \ n"
主机:127.0.0.1 \ r \ n"
用户代理:cdut-boy \ r \ n"
接受:text/html \ r \ n"
接受语言:zh-cn \ r \ n"
连接:保持活动状态\ r \ n";
5,recv(sock,buffer,499,0))可以从该函数获取日期吗?
我测试了一下,它不起作用,我什么也没得到.
有没有人可以帮助我?非常感谢!
How can I get the date form web after loading.
I use the socket, but can''t get the right date.
my code like follow:
1、 err = WSAStartup (0x0101, &WsaData);
2、 sock = socket (AF_INET, SOCK_STREAM, 0);
3、connect(sock,(LPSOCKADDR)&sin, sizeof(SOCKADDR_IN) )
4、send(sock,protocolHead,protocolHead.GetLength(),0)
in this step, I don''t know the value of protocolHead,and I set it like this
CString protocolHead = "GET /hsicpweb/Login.jsp HTTP/1.1\r\n"
"Host: 127.0.0.1\r\n"
"User-Agent: cdut-boy\r\n"
"Accept: text/html\r\n"
"Accept-Language: zh-cn\r\n"
"Connection: Keep-Alive \r\n";
5、recv(sock,buffer,499,0)) Can I get date from this function?
I tested it , it can''t work, I get nothing.
Is there anybody can help me? thx very much!
推荐答案
127.0.0.1==localhost
try another one.
regards.
我好几年没有使用套接字编程了.使用PERL或.NET可以很容易地解决您的问题.
I haven''t used socket programming in years. It''s fairly easy to solve your problem with PERL or .NET.
在VC6中,我使用下面的代码来获取日期和时间...
In VC6, I use the below code to get the date and time...
SYSTEMTIME st;
GetSystemTime(&st);
char date[20] = {0};
sprintf(date, "%d-%d-%d", st.wYear, st.wMonth, st.wDay);
希望这会有所帮助.
Hope this helps.
这篇关于加载后如何从网络获取日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!