#include
"mx.h"
#include "http.h"
int SendRequest
(MXMessage* pmessage, MXCom* pcom, void* AppField)
{
char slength[10];
char Request[250];
char* NumeroLT;
BUFFERPARM Buffer;
MXSetValue (pmessage,
"Request-Line", 1,
"GET http://sourceforge.net/tracker/?group_id=29057&atid=410216
HTTP/1.0");
MXSetValue (pmessage,
"Host", 1, "www.sourceforge.net");
MXSetValue (pmessage,
"Accept" , 1,
"image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel,\
application/msword, application/vnd.ms-powerpoint, */*");
MXSetValue (pmessage,
"Accept-Language",1, "fr");
MXSetValue (pmessage,
"Accept-Encoding",1, "gzip, deflate");
MXSetValue (pmessage,
"User-Agent", 1, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT)");
MXSetValue (pmessage,
"Proxy-Connection",1, "Keep-Alive");
MXSetValue (pmessage,
"Pragma" , 1, "no-cache");
return 1;
}
int RecvResponse (MXMessage* pmessage, MXCom* pcom, void* AppField)
{
BUFFERPARM* Buffer;
STRING Response;
int i = 0;
int j = 0;
Response =
(STRING)MXGetValue (pmessage, "Status-Line", 1);
Buffer = (BUFFERPARM*)MXGetValue (pmessage, "Content", 1);
/*
RETURN url is in Buffer->BufferContent */
FILE*f = fopen ("C:/response.html", "wt");
fwrite (buffer->BufferContent, 1, buffer->BufferSize, f);
fclose (f);
free (Buffer->BufferContent);
free (Buffer);
return 1;
}
void main ()
{
MX
mx;
MXMessage* pmessage;
MXCom* HTTPCom;
/*
Initialize MX manager */
MXInit (&mx, MXSERVER, NULL, NULL, 0, NULL);
/* Connect to http server */
HTTPCom = MXOpenTCP (&mx, "www.sourceforge.net", 80,
IPPROTO_HTTP, NULL, NULL, TRUE);
if (!HTTPCom) return;
MXAddComCallBack (&mx, HTTPCom, HTTP_SYS, "Response",MXONRECV,
RecvResponse, NULL);
MXAddComCallBack (&mx, HTTPCom, HTTP_SYS, "Request",
MXONSEND, SendRequest, NULL);
/*
Put message in queue */
pmessage = MXPutMessage (HTTPCom, HTTP_SYS, "Request");
MXDispatchEvents (&mx, 0);
MXEnd (&mx);
}
|