READ_URL@ problem with proxy servers
read_url@ contains the following line of C code...
session=InternetOpen('XXX',LOCAL_INTERNET_ACCESS,NULL,INTERNET_INVALID_PORT_NUMBER,
INTERNET_FLAG_DONT_CACHE);
The third argument of InternetOpen is set to NULL so there is no provision to provide the name of the proxy server.
I could provide the C code for the whole of the routine if you would like to adapt it to your needs. Alternatively I may be able to add a new routine if you can do the testing.
Thank you for the quick response. Please select one of the way that you suggested me.
You can also send me the C code. Please let me know what I need to do with that in order it to work for all my clients. I will try to see the result. If I do not succeed with that, I will ask you to include the code in the URL code.
Sincerely Prof. Shahram Montaser Kouhsari smk@intelectri.com
Here is some code based on the implementation of read_url@...
extern 'C' void __read_url(char* from, char* output, int mode, int& error)
{
HINTERNET session,rh;
FILE* f;
char buffer[8192];
unsigned long nn;
char* fom = 'w';
if(mode) fom = 'wb';
error = 1;
session = InternetOpen('XXX', LOCAL_INTERNET_ACCESS, NULL, INTERNET_INVALID_PORT_NUMBER,
INTERNET_FLAG_DONT_CACHE);
if(!session) return;
rh = InternetOpenUrl(session, from, NULL, 0xffffffff, 0x04000000, 42);
if(!rh) goto fin3;
f = fopen(output,fom);
if(!f) goto fin2;
while(1)
{
if(!InternetReadFile(rh,buffer,8192,&nn)) goto fin1;
if(nn == 0) break;
fwrite(buffer,nn,1,f);
}
error = 0;
fin1:
fclose(f);
fin2:
InternetCloseHandle(rh);
fin3:
InternetCloseHandle(session);
}
Hi Paul,
do I can compile your C code with SCC ? I'm interested in this solution because I need somehow access to the internet via proxy.
I have problems to resolve some symbols using SCC.. (e.g. InternetReadFile, HINTERNET)
The following code compiles using SCC...
#include <stdio.h>
typedef void* LPVOID;
typedef void* HINTERNET;
typedef const char* LPCSTR;
typedef unsigned int DWORD;
typedef int BOOL;
#define InternetOpen InternetOpenA
#define InternetOpenUrl InternetOpenUrlA
#define LOCAL_INTERNET_ACCESS 1
#define INTERNET_INVALID_PORT_NUMBER 0
#define INTERNET_FLAG_DONT_CACHE 0x04000000
HINTERNET __stdcall InternetOpenA(LPCSTR lpszAgent, DWORD dwAccessType, LPCSTR lpszProxy, LPCSTR lpszProxyBypass, DWORD dwFlags);
HINTERNET __stdcall InternetOpenUrlA(HINTERNET hInternet, LPCSTR lpszUrl, LPCSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD dwContext);
BOOL __stdcall InternetReadFile(HINTERNET hFile, LPVOID lpBuffer, DWORD dwNumberOfBytesToRead, DWORD* lpdwNumberOfBytesRead);
BOOL __stdcall InternetCloseHandle(HINTERNET hInternet);
extern 'C' void __read_url(char* from, char* output, int mode, int& error)
{
HINTERNET session,rh;
FILE* f;
char buffer[8192];
unsigned int nn;
char* fom = 'w';
if(mode) fom = 'wb';
error = 1;
session = InternetOpen('XXX', LOCAL_INTERNET_ACCESS, NULL, INTERNET_INVALID_PORT_NUMBER,
INTERNET_FLAG_DONT_CACHE);
if(!session) return;
rh = InternetOpenUrl(session, from, NULL, 0xffffffff, 0x04000000, 42);
if(!rh) goto fin3;
f = fopen(output,fom);
if(!f) goto fin2;
while(1)
{
if(!InternetReadFile(rh,buffer,8192,&nn)) goto fin1;
if(nn == 0) break;
fwrite(buffer,nn,1,f);
}
error = 0;
fin1:
fclose(f);
fin2:
InternetCloseHandle(rh);
fin3:
InternetCloseHandle(session);
}
Thx Paul for the Code. The compile works but during the link process I get a warning: WARNING the following symbols are missing:
InternetOpenA InternetOpenUrlA InternetReadFile InternetCloseHandle
Do I have link against something...?
Yes, you will need to load Wininet.dll when linking.
Thx Paul, everything is working fine for me now.