[LUAU] Help needed with a c program
Matt Darnell
mattdarnell at gmail.com
Sun Dec 18 18:43:39 PST 2005
Aloha,
I am looking for sample c code that connects to a URL. I tried to cobble
something together but it isn't working out too well.
All it needs to do is connect to a url like "
https://www.example.com/sample?option1=matt%option2=darnell%option3=please_help
"
The web server will do he rest from there. All the app has to do is connect
to the web site, no need to get anything back.
Below is what I tried to hack out of a web browser I found on the web.
Aloha,
Matt
************
#include <winsock.h>
WSADATA WSData;
SOCKET s;
struct hostent *H;
SOCKADDR_IN socket_in;
char url[1000];
char host[1000]; // host name
char method[50];
char header[1000];
char *abs_path; // abs path URI
char request[1000];
HWND hwnd,hEdit,hUrl,hMain,hStatus,hTool,hGo;
void AddLogEntry(HWND hwnd,char * entry);
HFONT hfFont;
char buffer[100000];
long bufferSize=0;
char hostent_buffer[MAXGETHOSTSTRUCT];
HANDLE HR;
/*
The Windows Sockets 'WSAStartup' function initiates use
of
the Windows Sockets DLL by a process.
This function must be the first Windows Sockets function
called by an application or DLL. It allows an
application
or DLL to specify the version of Windows Sockets
required
and to retrieve details of the specific Windows Sockets
implementation. The application or DLL may only issue
further Windows Sockets functions after a successful
WSAStartup invocation.
*/
d = WSAStartup(0x101,&WSData);
{
H=(struct hostent*)hostent_buffer;
socket_in.sin_addr.s_addr = *((unsigned long *)
H->h_addr);
sprintf(method,"GET");
// Request-Line
sprintf(request,"%s %s %s\r\n",method,uri.abs_path
,"HTTP/1.1");
// request-headers
sprintf(header,"Host: %s\r\n",uri.host);
strcat(request,header);
sprintf(header,"Connection: close\r\n");
strcat(request,header);
// headers end
strcat(request,"\r\n");
/*
The Windows Sockets 'connect' function establishes a
connection to a peer.
*/
d = connect(s, (struct sockaddr *)&socket_in ,
sizeof(socket_in));
/*
The Windows Sockets 'send' function sends data on a
connected socket.
*/
send(s,request,sizeof(request),0);
//fp = fopen("file.tmp","w+"); // save incomming data to
disk
hFileHeaders=CreateFile(headersCacheFileName,GENERIC_READ|GENERIC_WRITE,
FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,CREATE_ALWAYS ,0,NULL);
hFileBody=CreateFile(bodyCacheFileName,GENERIC_READ|GENERIC_WRITE,
FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,CREATE_ALWAYS ,0,NULL);
WSAAsyncSelect(s,hwnd,CM_READ_SOCKET,FD_READ|FD_CLOSE);
}
More information about the LUAU
mailing list