|
forums.silverfrost.com Welcome to the Silverfrost forums
|
View previous topic :: View next topic |
Author |
Message |
Shahram
Joined: 13 May 2013 Posts: 25
|
Posted: Mon May 13, 2013 7:43 pm Post subject: READ_URL@ problem with proxy servers |
|
|
I have used the function CALL READ_URL@(URL,FILE,MODE,IERROR) to receive an ID of my client from MYSQL server. It works fine, but if my client is using Proxy this function returns internet error. Would you please guide me how I can use it with proxyservers.[url][/url] |
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7925 Location: Salford, UK
|
Posted: Tue May 14, 2013 8:50 am Post subject: |
|
|
read_url@ contains the following line of C code...
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. |
|
Back to top |
|
|
Shahram
Joined: 13 May 2013 Posts: 25
|
Posted: Tue May 14, 2013 2:22 pm Post subject: |
|
|
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 |
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7925 Location: Salford, UK
|
Posted: Tue May 14, 2013 3:53 pm Post subject: |
|
|
Here is some code based on the implementation of read_url@...
Code: | 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);
}
|
|
|
Back to top |
|
|
dgurok
Joined: 26 May 2011 Posts: 66
|
Posted: Wed Oct 21, 2015 9:58 am Post subject: |
|
|
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) |
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7925 Location: Salford, UK
|
Posted: Wed Oct 21, 2015 11:50 am Post subject: |
|
|
The following code compiles using SCC...
Code: | #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);
} |
|
|
Back to top |
|
|
dgurok
Joined: 26 May 2011 Posts: 66
|
Posted: Thu Oct 22, 2015 9:25 am Post subject: |
|
|
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...? |
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7925 Location: Salford, UK
|
Posted: Thu Oct 22, 2015 6:19 pm Post subject: |
|
|
Yes, you will need to load Wininet.dll when linking. |
|
Back to top |
|
|
dgurok
Joined: 26 May 2011 Posts: 66
|
Posted: Fri Oct 23, 2015 11:52 am Post subject: |
|
|
Thx Paul, everything is working fine for me now. |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|