Hi,
I am using this function:

function GetInetFile (const fileURL, FileName: String): boolean;
const
  BufferSize = 1024;
var
  hSession, hURL: HInternet;
  Buffer: array[1..BufferSize] of Byte;
  BufferLen: DWORD;
  f: File;
  sAppName: string;
begin
 result := false;
 sAppName := ExtractFileName(Application.ExeName) ;
 hSession := InternetOpen(PChar(sAppName), INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0) ;
 try
  hURL := InternetOpenURL(hSession, PChar(fileURL), nil, 0, 0, 0) ;
  try
   AssignFile(f, FileName) ;
   Rewrite(f,1) ;
   repeat
    InternetReadFile(hURL, @Buffer, SizeOf(Buffer), BufferLen) ;
    BlockWrite(f, Buffer, BufferLen)
   until BufferLen = 0;
   CloseFile(f) ;
   result := True;
  finally
   InternetCloseHandle(hURL)
  end
 finally
  InternetCloseHandle(hSession)
 end
end;

to download file from my server. I made some changes in this function, to display progress bar and I put this function into the thread class.

But I need to setup username and password if the local network requires username and password.

PS: This function is in the WinInet interface.

Any solution?

But I need to setup username and password if the local network requires username and password.

I cannot help you much more, but take a look in InternetConnect function (from msdn).

bye

But I am using the InternetOpen function, not the InternetConnect.

But I am using the InternetOpen function, not the InternetConnect.

As I have said, I cannot help you much more, because I cannot try an implementation for this case. But, I think you could replace InternetOpen by InternetConnect function.
If You looked at msdn link that I have put, You must have seen that it this last receive User and Password as params to connect - don't are that You need?

The function header from WinInet unit:

function InternetConnect(hInet: HINTERNET; lpszServerName: PChar;
  nServerPort: INTERNET_PORT; lpszUsername: PChar; lpszPassword: PChar;
  dwService: DWORD; dwFlags: DWORD; dwContext: DWORD): HINTERNET; stdcall;

From the msdn site:
Function goal:
Opens an File Transfer Protocol (FTP), Gopher, or HTTP session for a given site. (I understood it is that You want)

Parameters:
hInternet - Handle returned by a previous call to InternetOpen. (You are using than)
lpszUsername - Pointer to a null-terminated string that specifies the name of the user to log on. If this parameter is NULL, the function uses an appropriate default, except for HTTP; a NULL parameter in HTTP causes the server to return an error. For the FTP protocol, the default is "anonymous".
lpszPassword - Pointer to a null-terminated string that contains the password to use to log on. If both lpszPassword and lpszUsername are NULL, the function uses the default "anonymous" password. In the case of FTP, the default password is the user's e-mail name. If lpszPassword is NULL, but lpszUsername is not NULL, the function uses a blank password.
and so on...

Maybe You can try...

Bye

Ok, so I used function InternetOpen at first, than the HINTERNET handle returned by this function, I used in InternetConnect function with blank username and blank password. Because I don't need the password request now.

And what...
Nothing, file "downloaded.txt" was created but with no content from the internet. So I put InternetConnect as a comment, run application and "downloaded.txt" had all the source from the internet.

How can I use the InternetConnect function? It doesn't want to work..

Ok, so I used function InternetOpen at first, than the HINTERNET handle returned by this function, I used in InternetConnect function with blank username and blank password. Because I don't need the password request now.

And what...
Nothing, file "downloaded.txt" was created but with no content from the internet. So I put InternetConnect as a comment, run application and "downloaded.txt" had all the source from the internet.

How can I use the InternetConnect function? It doesn't want to work..

Ok.
I have searched for some example that help you and I found one at Torry's Delphi Pages (link). It will show how to use this function to get a file by using ftp transfer protocol.

Bye

I found this same example on Google. But this example is for ftp transfer, I don't need to know tha way of ftp connect. I need the http authentication. For example if you're in work, or in school, the internet service provider may block all the websites within some websites as school homepage, or the webmail client. I need to resolve this problem.

This article has been dead for over six months. Start a new discussion instead.