Silverfrost Forums

Welcome to our forums

READ_URL@ problem with proxy servers

13 May 2013 6:43 #12209

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.

14 May 2013 7:50 #12212

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.

14 May 2013 1:22 #12214

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

14 May 2013 2:53 #12215

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);
}
21 Oct 2015 8:58 #16943

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)

21 Oct 2015 10:50 #16944

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); 
} 
22 Oct 2015 8:25 #16946

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...?

22 Oct 2015 5:19 #16947

Yes, you will need to load Wininet.dll when linking.

23 Oct 2015 10:52 #16951

Thx Paul, everything is working fine for me now.

Please login to reply.