char m_URL[256], m_ProxyServer[256], m_Path[256], m_SaveToFile[256];//define charecter buffer of 256 to read url, path to save file, file name and proxy server name if it is
long l_ProxyPort;//define proxy port, if it is
printf("\r\nEnter URL = ");
gets(m_URL);//read url
printf("\r\nEnter Proxy Server = ");
gets(m_ProxyServer);//read proxy server
printf("\r\nEnter Proxy Port = ");
scanf("%d", &l_ProxyPort);
getchar();
printf("\r\nEnter Path = ");
gets(m_Path);//read path where output file will be saved
printf("\r\nEnter File Name = ");
gets(m_SaveToFile);//read file name
try//for COM library call, try...catch is used to handle exceptions
{
IHTTPPtr obj;//take smart pointer object obj for COM library
CoInitialize(NULL);//Initializes the COM library on the current thread
obj = IHTTPPtr("AdvHTTP.HTTP");
obj->PutURL(m_URL);//set url property
obj->PutProxyServer(m_ProxyServer);//set proxy server property
obj->put_ProxyPort(l_ProxyPort);//set proxy server port property
obj->PutPath(m_Path);//set path property
obj->PutSaveToFile(m_SaveToFile);//set file name property
IDispatch *p = obj->Get();//call Get method of COM library
//call GetIsError() property of COM library and check its value, if its value is 1, then
//GetErrorReason() property of COM will contain error message, for which this error occured
char m_URL[256], m_ProxyServer[256], m_Path[256], m_SaveToFile[256], m_FormFieldName[256], m_FormFieldValue[256];//define charecter buffer of 256 to read url, path to save file, for field name, value, file name and proxy server name if it is
long l_ProxyPort;//define proxy port, if it is
printf("\r\nEnter URL = ");
gets(m_URL);//read url
printf("\r\nEnter Proxy Server = ");
gets(m_ProxyServer);//read proxy server
printf("\r\nEnter Proxy Port = ");
scanf("%d", &l_ProxyPort);
getchar();
printf("\r\nEnter Path = ");
gets(m_Path);//read path where output file will be saved
printf("\r\nEnter File Name = ");
gets(m_SaveToFile);//read file name
printf("\r\nEnter Form Field Name = ");
gets(m_FormFieldName);//read form field name to be posted
printf("\r\nEnter Form Field Value = ");
gets(m_FormFieldValue);//read value for form field variable
try//for COM library call, try...catch is used to handle exceptions
{
IHTTPPtr obj;//take smart pointer object obj for COM library
CoInitialize(NULL);//Initializes the COM library on the current thread
obj = IHTTPPtr("AdvHTTP.HTTP");
obj->PutURL(m_URL);//set url property
obj->PutProxyServer(m_ProxyServer);//set proxy server property
obj->put_ProxyPort(l_ProxyPort);//set proxy server port property
obj->PutPath(m_Path);//set path property
obj->PutSaveToFile(m_SaveToFile);//set file name property
obj->FormField(m_FormFieldName, m_FormFieldValue);//set form field method to post form variables
// you can also write code here for posting URL variables and file also
IDispatch *p = obj->Post();//call Post method of COM library
//call GetIsError() property of COM library and check its value, if its value is 1, then
//GetErrorReason() property of COM will contain error message, for which this error occured