Click here to Skip to main content
15,892,537 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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!
Posted

VB
127.0.0.1==localhost
try another one.
regards.
 
Share this answer
 
Comments
fjdiewornncalwe 3-Feb-11 10:51am    
Great catch. I didn't see that at first either.
mbue 3-Feb-11 13:58pm    
sorry, codeproject auto format ;)
I haven't used socket programming in years. It's fairly easy to solve your problem with PERL or .NET.
 
Share this answer
 
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.
 
Share this answer
 
Comments
fjdiewornncalwe 3-Feb-11 10:50am    
He doesn't want the local system time, he wants to retrieve the time from the web.
fjdiewornncalwe 3-Feb-11 10:50am    
Moved from OP's answer: I want to get the date from web. not system. Sigh

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900