Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

username-password detection

MarlonMarlon Member Posts: 6
Hi everyone,

Can someone tell me how to approach the following 2 problems.

1) Via my Visual basic application i want to enter a specific Internet site. When entering this page, a dialog box comes up to fill in your username and password. How can i detect if a internet site requires a
username and password and how do i fill in the username and password automatically.

2) how can i a request a file for downloading if this internet page has no FTP-site?


Thanks!!

Comments

  • iDaZeiDaZe Member Posts: 464
    : Hi everyone,
    :
    : Can someone tell me how to approach the following 2 problems.
    :
    : 1) Via my Visual basic application i want to enter a specific Internet site. When entering this page, a dialog box comes up to fill in your username and password. How can i detect if a internet site requires a
    : username and password and how do i fill in the username and password automatically.
    :
    : 2) how can i a request a file for downloading if this internet page has no FTP-site?
    :
    :
    : Thanks!!
    :

    1. If a password is required, the server sends the request for one back in the header. How you read this depends on what you're using for your program to contact the site (Some OCX, WinInet API calls, etc ...)

    2. Just use the url of the file (ie. http://www.somesite.com/somefile.zip)

    What are you using as internet component ? I'm assuming your not using WinInet API calls, so some OCX. Or haven't you decided yet ?

  • MarlonMarlon Member Posts: 6
    : : Hi everyone,
    : :
    : : Can someone tell me how to approach the following 2 problems.
    : :
    : : 1) Via my Visual basic application i want to enter a specific Internet site. When entering this page, a dialog box comes up to fill in your username and password. How can i detect if a internet site requires a
    : : username and password and how do i fill in the username and password automatically.
    : :
    : : 2) how can i a request a file for downloading if this internet page has no FTP-site?
    : :
    : :
    : : Thanks!!
    : :
    :
    : 1. If a password is required, the server sends the request for one back in the header. How you read this depends on what you're using for your program to contact the site (Some OCX, WinInet API calls, etc ...)
    :
    : 2. Just use the url of the file (ie. http://www.somesite.com/somefile.zip)
    :
    : What are you using as internet component ? I'm assuming your not using WinInet API calls, so some OCX. Or haven't you decided yet ?
    :
    :

    I do use the functions in WinInet.

    This is the link to that file.
    (This link is associate with an ICON and will open as an excel session in the internet browser when you click on it. the only way to save this file to disk, is to right click on that icon and save that file). But how can i retrieve this file in code.?

    Link to the file:

    www.copaco.nl/q-web/prijslst.nsf/00255f4a006e161180255df7004f4936/c04283a88a
    119b0c4125674500533107/$FILE/HP up-to-date.xls

    This is the code i use where, sFile is the file in the above string.
    FtpGetFile(hInternetConnect, sFile, "c: est.xls", 0, 0, 2, 0)

    But this does not work.

  • iDaZeiDaZe Member Posts: 464
    :
    : I do use the functions in WinInet.
    :
    : This is the link to that file.
    : (This link is associate with an ICON and will open as an excel session in the internet browser when you click on it. the only way to save this file to disk, is to right click on that icon and save that file). But how can i retrieve this file in code.?
    :
    : Link to the file:
    :
    : www.copaco.nl/q-web/prijslst.nsf/00255f4a006e161180255df7004f4936/c04283a88a
    : 119b0c4125674500533107/$FILE/HP up-to-date.xls
    :
    : This is the code i use where, sFile is the file in the above string.
    : FtpGetFile(hInternetConnect, sFile, "c: est.xls", 0, 0, 2, 0)
    :
    : But this does not work.
    :
    :

    That's because your trying to use FTP protocols to access a HTTP server. You should use the Http functions or even the 'basic' WinInet functions.

    Here's an example (in Delphi, sorry, my VB is a bit rusty, if someone here can translate please ?)
    [code]
    function GetHttp(AUrl, ATargetFile: String; AInternetHandle: HINTERNET): Boolean;
    var
    PageHandle: HINTERNET;
    f: file;
    Buf: array[1..1024] of Byte;
    BufLen: Cardinal;
    begin
    try
    try
    PageHandle := InternetOpenUrl(AInternetHandle, PChar(AUrl), nil, 0, 0, 0);
    if PageHandle = nil then
    MessageBox(0, 'Failed to get requested Url', 'Error', MB_ICONERROR)
    else begin
    AssignFile(f, ATargetFile);
    Rewrite(f, 1);
    repeat
    InternetReadFile(PageHandle, @Buf, 1024, BufLen);
    BlockWrite(f, Buf, BufLen);

    // right here would be a good idea to place something like DoEvents

    until BufLen = 0;
    CloseFile(f);
    Result := True
    end
    except
    Result := False
    end
    finally
    InternetCloseHandle(PageHandle)
    end
    end;
    [/code]
    Basicly what it does is:
    1. Open a handle to the given file on the server with InternetOpenUrl()
    2. Then use InternetReadFile() to read chunks of data from that file and write it to a local file.
    3. Close the handle to the file withe InternetCloseHandle().

    btw. BlockWrite() is a Delphi procedure for writing data to a binary file, but I'm sure VB has something similair.
  • MarlonMarlon Member Posts: 6
    : :
    : : I do use the functions in WinInet.
    : :
    : : This is the link to that file.
    : : (This link is associate with an ICON and will open as an excel session in the internet browser when you click on it. the only way to save this file to disk, is to right click on that icon and save that file). But how can i retrieve this file in code.?
    : :
    : : Link to the file:
    : :
    : : www.copaco.nl/q-web/prijslst.nsf/00255f4a006e161180255df7004f4936/c04283a88a
    : : 119b0c4125674500533107/$FILE/HP up-to-date.xls
    : :
    : : This is the code i use where, sFile is the file in the above string.
    : : FtpGetFile(hInternetConnect, sFile, "c: est.xls", 0, 0, 2, 0)
    : :
    : : But this does not work.
    : :
    : :
    :
    : That's because your trying to use FTP protocols to access a HTTP server. You should use the Http functions or even the 'basic' WinInet functions.
    :
    : Here's an example (in Delphi, sorry, my VB is a bit rusty, if someone here can translate please ?)
    : [code]
    : function GetHttp(AUrl, ATargetFile: String; AInternetHandle: HINTERNET): Boolean;
    : var
    : PageHandle: HINTERNET;
    : f: file;
    : Buf: array[1..1024] of Byte;
    : BufLen: Cardinal;
    : begin
    : try
    : try
    : PageHandle := InternetOpenUrl(AInternetHandle, PChar(AUrl), nil, 0, 0, 0);
    : if PageHandle = nil then
    : MessageBox(0, 'Failed to get requested Url', 'Error', MB_ICONERROR)
    : else begin
    : AssignFile(f, ATargetFile);
    : Rewrite(f, 1);
    : repeat
    : InternetReadFile(PageHandle, @Buf, 1024, BufLen);
    : BlockWrite(f, Buf, BufLen);
    :
    : // right here would be a good idea to place something like DoEvents
    :
    : until BufLen = 0;
    : CloseFile(f);
    : Result := True
    : end
    : except
    : Result := False
    : end
    : finally
    : InternetCloseHandle(PageHandle)
    : end
    : end;
    : [/code]
    : Basicly what it does is:
    : 1. Open a handle to the given file on the server with InternetOpenUrl()
    : 2. Then use InternetReadFile() to read chunks of data from that file and write it to a local file.
    : 3. Close the handle to the file withe InternetCloseHandle().
    :
    : btw. BlockWrite() is a Delphi procedure for writing data to a binary file, but I'm sure VB has something similair.
    :

    Thanks you for your fast reply,

    I tried your code which i rewrote in visual basic, but when i use InternetOpenUrl i don't get a handle to that file. To be more specific,
    when i put my mouse pointer over the icon (which is associated to a file) the internet browser shows the following address in the status bar at the bottom;

    "https://www.copaco.nl/q-web/prijslst.nsf/00255f4a006e161180255df7004f4936/c04283a88a119b0c4125674500533107/$FILE/HP up-to-date.zip"

    Is this the string which i have to send as a parameter?
    Is HTTP function HttpOpenRequest also an alternative to retrieve a file?




  • iDaZeiDaZe Member Posts: 464
    :
    : Thanks you for your fast reply,
    :
    : I tried your code which i rewrote in visual basic, but when i use InternetOpenUrl i don't get a handle to that file. To be more specific,
    : when i put my mouse pointer over the icon (which is associated to a file) the internet browser shows the following address in the status bar at the bottom;
    :
    : "https://www.copaco.nl/q-web/prijslst.nsf/00255f4a006e161180255df7004f4936/c04283a88a119b0c4125674500533107/$FILE/HP up-to-date.zip"
    :
    : Is this the string which i have to send as a parameter?
    : Is HTTP function HttpOpenRequest also an alternative to retrieve a file?
    :
    :
    :

    Ah, I see the problem. I should have mentioned it before, but there is a function called InternetCanonicalizeUrl(), which converts all 'unsafe' characters in the url to 'escaped' characters (for instance, a space is converted to %20). So you would need to put the url through that function first and then call InternetOpenUrl().

    In Delphi it would look something like this:
    [code]
    function SafeUrl(AUrl: String): String;
    var
    p: PChar;
    i: Integer;
    begin
    i := 255;
    GetMem(p, i);
    if not InternetCanonicalizeUrl(PChar(AUrl), p, i, 0) then
    if GetLastError = ERROR_INSUFFICIENT_BUFFER then begin
    // buffer is to small, i now contains correct size
    GetMem(p, i)
    InternetCanonicalizeUrl(PChar(AUrl), p, i, 0)
    end else
    MessageBox(0, 'Failed to convert Url', Error'', MB_ICONERROR);
    Result := String(p);
    FreeMem(p)
    end;
    [/code]
  • Shawn CarterShawn Carter Member Posts: 0

    __ / http://forcoder.org / free ebooks and video tutorials about // C#, Ruby, Python, Assembly, PHP, MATLAB, Visual Basic, Visual Basic .NET, Perl, C, Go, Delphi, Objective-C, R, Java, JavaScript, Scratch, Swift, C++, PL/SQL Clojure, Crystal, SAS, Erlang, LabVIEW, FoxPro, ML, Julia, Scala, Rust, Logo, Scheme, Lua, Ada, Apex, VBScript, Alice, Awk, Fortran, ABAP, D, Hack, Lisp, F#, Transact-SQL, COBOL, Prolog, Kotlin, Dart, Bash //

Sign In or Register to comment.