Hi I have got a problem i need to send a http 1.0 post message to a perl script. The Problem is i have never done WinSock Programming before. Is there any nice tutorial about this out there. Or if it isn't to much to do could someone give me some example source with comments on how to do this. sign CyBerian
Check Iczelion's WinSock tut and HTTP example code by him. Already read them?? If not, read them :) see also : http://www.cyberport.com/~tangent/programming/winsock/
Icz's HTTP (zip) downloader is a good example for this.. All you need to do is make a POST header with proper data that you'll send, something like:
check the HTTP protocol RFC for more info on the headers: Hypertext Transfer Protocol -- HTTP/1.0 i hope this helped ya, good luck
.data DataBuffer db 256 dup (0) ;buffer that will contain the POST header and the data to send. Data db "login=asm&passwd=rocks",0 ;the data to send PostTemplate db "POST /url/blah HTTP/1.0",0Dh,0Ah ;POST db "User-Agent: MyClient",0Dh,0Ah db "Host: www.hosttosendto.net",0Dh,0Ah ;host db "Content-Length: %i",0Dh,0Ah ;data length db "Connection: Keep-Alive",0Dh,0Ah,0Dh,0Ah db "%s",0 ;the data .code ... ... invoke lstrlen, addr Data ;get data length invoke sprintf, addr DataBuffer, addr PostTemplate, eax, addr Data ;create the header+proper data invoke lstrlen, addr DataBuffer ;get length to send invoke send, sock, addr DataBuffer, eax, 0 ;send..
thx. a lot i should take a better look at iczelions tuts :) I think this will guide to the proper transfer i need :) sign CyBerian
hello... i am also interested in learning how to receive or send data from/to scripts|web-pages. i know how to use winsock but i am not familar with those protocol headers. by the way: if a script returns data to me how does it know the right destination and the port??? now you can say something like: look at icz http downloader or read thoses rfc's but these documents are so big that i would be busy for one month... don't you know some other tut's on this topic or can you send me some examples? -would be very happy :) thank you & bye.
Greetings drcmda, I'm not really familiar with rfc listings. I suggest you get a packet sniffer (etherpeek is a good win32 sniffer) and sniff out the headers HTTP clients/servers use. That's what I do to unlock the sequence of protocols and it's been a great help to me. And the answer to your question, how does the server know which client port to send data to ? well, it's the TCP/IP's craft. Both sides exchange information by the use of packets, and the initial packets in the connection sequence include the port and address information. When a client makes a connection request to a server, there is a part in the sequence where it sends in the port where the server should send back info. Some Sock Info, hope that you would find use with any of these: www.stardust.com (winsock, ipv6, and more...) www.sockaddr.com (great site, has some examples) www.sockets.com - clip This message was edited by clip, on 3/12/2001 8:02:16 PM
thank you ... :) i thought that the return informations must be stored in the protocol... now i understand. on one of these sites you gave me i found a little http file downloader - very good, this is exactly what i wanted to learn a little bit more about these protocols.
glad to have helped you
uhm ... little bit late but here's my aproach after learning those http prot headers. the following prog writes data to a simple guestbook script (blocked mode)... the gb is located @ http://gb.xodox.com/cgi-bin/guestbook.cgi?id=RomBln - erm, you may think i'm bad now because i spam gb's from another people but this romantik19 guy is some military-weapon freak and i know him in person so i know what i do :)
This message was edited by drcmda, on 3/15/2001 9:27:07 AM
.386 .model flat, stdcall option casemap :none include \masm32\include\windows.inc include \masm32\include\wsock32.inc include \masm32\include\user32.inc include \masm32\include\kernel32.inc includelib \masm32\lib\user32.lib includelib \masm32\lib\kernel32.lib includelib \masm32\lib\wsock32.lib .DATA wsadata WSADATA <> sin sockaddr_in <> HostName db "gb.xodox.com",0 HPort dd 80 PostTemplate db "POST /cgi-bin/guestbook.cgi HTTP/1.0",0Dh,0Ah db "User-Agent: BLA",0Dh,0Ah db "Host: %s",0Dh,0Ah db "Content-Type: application/x-www-form-urlencoded",0Dh,0Ah db "Content-Length: %i",0Dh,0Ah,0Dh,0Ah Data db "cmd=write&" db "id=RomBln&" db "name=romatikboy19_i_hate_you&" db "email=&" db "url=&" db "comment=" Cmt db "get_a_life_retard",0 Error db "ERROR -> aborting!",0 Caption db "written by drcmda",0 .DATA? sock dd ? DataBuffer db 500 dup (?) .CODE start: invoke WSAStartup, 101h,addr wsadata cmp eax,NULL jnz @@error invoke socket,AF_INET,SOCK_STREAM,0 cmp eax,INVALID_SOCKET jz @@error mov sock,eax mov sin.sin_family, AF_INET invoke htons, HPort mov sin.sin_port,ax invoke gethostbyname, addr HostName mov eax, mov eax, mov eax, mov sin.sin_addr,eax invoke connect,sock,addr sin,sizeof sin cmp eax,SOCKET_ERROR jz @@error invoke lstrlen, addr Data invoke wsprintf,addr DataBuffer,addr PostTemplate, addr HostName, eax invoke lstrlen,addr DataBuffer invoke send, sock, addr DataBuffer, eax, 0 cmp eax,SOCKET_ERROR jz @@error invoke recv,sock,addr DataBuffer,sizeof DataBuffer,0 invoke MessageBox,NULL,addr DataBuffer,addr Caption,MB_OK jmp @@exit @@error: invoke MessageBox,NULL,addr Error,addr Caption,MB_OK @@exit: invoke closesocket,sock invoke WSACleanup invoke ExitProcess,NULL END start