Results 1 to 36 of 36

Thread: filing out the form to a hidden webpage.

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2001
    Posts
    131

    filing out the form to a hidden webpage.

    Ok, I need to use http to upload files. I have tried many times with the inet control. But it refuses to work. So I was wondering. How would I go about filing out the form of a form to a hidden webcontrol page?

    I need to do it to send data to a linux server for processing and stuff. But I'm new to vb and have to clue how to go about this. An example would be nice also if possable..

  2. #2
    PowerPoster
    Join Date
    Jan 2001
    Location
    Florida
    Posts
    3,216
    I don't understand what u are asking?

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Aug 2001
    Posts
    131
    I want to fill out a web form (using the webcontrol) and send it out. I just noticed someone asked the same question, and was wondering if this would work now..

    Code:
    Private Sub cmdSubmit_Click()
    WebBrowser1.Navigate "http://www.vi2.com/cgi-bin/uploadMF"
    Do
      DoEvents
    Loop Until Not WebBrowser1.Busy
    With WebBrowser1.Document
        .All("name").Value = "Whatever"
        .All("comment").Value =  "whatever"
        .All("info").Value =  "whatever"
        .All("email").Value =  "whatever"
        .Forms(0).submit
    End With
    End Sub

  4. #4
    Frenzied Member
    Join Date
    Mar 2001
    Location
    You are HERE •™
    Posts
    1,300
    Dr.Sparkle -

    Can you post the URL of the web-page that your trying to work with?
    Edit: Whoops we must have cross-posted...I see your code now.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Aug 2001
    Posts
    131
    This is the webpage..

    http://www.vi2.com/maxForumFiles/

    We will be adding more features soon. Like name, e-mail, saved config for later deletion and stuff. It will all be added to a db backend..

    That's why it nly has a description field right now..

  6. #6
    Fanatic Member
    Join Date
    Sep 2000
    Location
    UK.
    Posts
    728

    Crash course in HTTP Protocol

    Your best option is to get low down and dirty with the HTTP Protocol...

    If you need to upload form data to an HTTP server, there are two options available: POST and GET.

    Post is preferred, as the data isn't stored in the URL as with GET... POST also supports the upload of files... The following examples detail how you would go about uploading form information...

    Example of using HTTP GET Method
    Code:
    'Assumes Form fields named txtName and txtEmail
    strData = "GET /Data.cgi?txtName=Digital+X%2DTreme&txtEmail=digital%5Fx%[email protected] HTTP/1.1" & vbCrlf
    strData = strData & "ADDITIONAL HTTP HEADER INFO" & vbcrlf & vbcrlf
    'Connect to HTTP Server, then send
    Winsock.SendData strData
    Example using HTTP POST Method
    Code:
    'Assumes Form fields named txtName and txtEmail
    strData = "POST /Data.cgi HTTP/1.1" & vbCrlf
    strData = strData & "ADDITIONAL HTTP HEADER INFO" & vbcrlf & vbcrlf
    strData = stRData & "txtName=Digital+X%2DTreme&txtEmail=digital%5Fx%[email protected]" 
    'Connect to HTTP Server, then send
    Winsock.SendData strData
    Uploading a file i similar, but encoding it in the correct format is trickier. Below is an example of the data that is sent to an HTTP Server when a file is posted... The file is a small text file.

    POST /upload.cgi HTTP/1.1
    Content-Type: multipart/form-data; boundary=---------------------------7d1226321c8
    Content-Length: 315

    -----------------------------7d1226321c8
    Content-Disposition: form-data; name="fileFIELD"; filename="D:\Documents\Hello_World.txt"
    Content-Type: text/plain

    Hello World!
    -----------------------------7d1226321c8--
    Anyway, that is the format you would need to send the file upload in to an HTTP server. If you need more help, post back

    Laterz
    Digital-X-Treme
    Contact me on MSN Messenger: [email protected]

    [VBCODE]Debug.Print Round(((1097) - ((55 ^ 5 + 311 ^ 3 - 11 ^ 3) _
    / (68 ^ 5))) ^ (1 / 7), 13)[/VBCODE]

  7. #7
    Frenzied Member
    Join Date
    Mar 2001
    Location
    You are HERE •™
    Posts
    1,300
    Well......this code may work. I'm not sure, I managed to get it to submit for me, but I recieved an internal error. I'm guessing because of the Value "C:\whatever\whatever.jpg". Try changing this to a valid value and see if it works for you. I didn't want to upload a file.

    You may want to go with Digital-X-Treme's code using a Winsock Control.

    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Command1_Click()
    4.     WebBrowser1.Navigate "http://www.vi2.com/maxForumFiles/"
    5. End Sub
    6.  
    7. Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
    8.     If (pDisp Is WebBrowser1.Object) Then
    9.         If URL = "http://www.vi2.com/maxForumFiles/" Then
    10.             Debug.Print "yeah"
    11.             With WebBrowser1.Document
    12.                 .Forms("FilePost").upfile.Value = "C:\whatever\whatever.jpg"
    13.                 .Forms("FilePost").Description.Value = "250 character description"
    14.                 .Forms("FilePost").submit
    15.             End With
    16.         End If
    17.     End If
    18. End Sub

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Aug 2001
    Posts
    131
    Well, my proggy already mis going to be required to use the webcontrol. So I figured I would use it for everything, instead of adding extra controls just to type out even more code..

    So it still stands, will my code snippit work?

  9. #9
    Fanatic Member
    Join Date
    Sep 2000
    Location
    UK.
    Posts
    728

    Why

    Why do you need to use the WebBrowser control...? Surely you can choose to use the components that do the job, quickly and efficiently... Using the method i described wont be that much more code, and it will allow you direct access to the server, without having to mess about using the Web Browser control

    Laterz
    Digital-X-Treme
    Contact me on MSN Messenger: [email protected]

    [VBCODE]Debug.Print Round(((1097) - ((55 ^ 5 + 311 ^ 3 - 11 ^ 3) _
    / (68 ^ 5))) ^ (1 / 7), 13)[/VBCODE]

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Aug 2001
    Posts
    131

    Re: Why

    Originally posted by [Digital-X-Treme]
    Why do you need to use the WebBrowser control...? Surely you can choose to use the components that do the job, quickly and efficiently... Using the method i described wont be that much more code, and it will allow you direct access to the server, without having to mess about using the Web Browser control

    Laterz
    Th webcontrol is being used for a different part of the proggy. To display a php generated page to display db query results.. inless you know of a way to get the result and parse the page without using the webcontrol then I will use it. I figure I don't want to add even more code and controsl inless I have to..

    That, and I wouldn't even begain to know how to parse an html page to grab the info I need..

  11. #11
    Frenzied Member
    Join Date
    Mar 2001
    Location
    You are HERE •™
    Posts
    1,300
    Your code won't work as it stands. If you use the code snippet I provided it should work.

    Question: Has the "Upload" feature been implemented on the website already? The reason I ask is I just tryed to upload a valid file, and I recieved an internal error. Do I need to be logged in? I tried upping a 200kb zip file, and it appeared to be uploading, but then I recieved the internal error. Any idea why this occured?

  12. #12

    Thread Starter
    Addicted Member
    Join Date
    Aug 2001
    Posts
    131
    The server got hammered by some serves in the same node that got the codred virus.. so he took the pic hosting part down for a little while to save his badwidth..

    It does work though.. The whole backend is being written in php though.. with a mysql db to hold names, coments emails and the such..

    do you know how I could get that code I posted to work?

  13. #13
    Frenzied Member
    Join Date
    Mar 2001
    Location
    You are HERE •™
    Posts
    1,300
    Here ya go:
    VB Code:
    1. Private Sub cmdSubmit_Click()
    2.     WebBrowser1.Navigate "http://www.vi2.com/maxForumFiles/"
    3.     Do
    4.         DoEvents
    5.     Loop Until WebBrowser1.ReadyState = READYSTATE_COMPLETE
    6. If WebBrowser1.LocationURL = "http://www.vi2.com/maxForumFiles/" Then
    7.     With WebBrowser1.Document
    8.         .Forms("FilePost").upfile.Value = "C:\whatever\whatever.jpg"
    9.         .Forms("FilePost").Description.Value = "250 character description"
    10.         .Forms("FilePost").submit
    11.     End With
    12. End If
    13. End Sub

    Another option, and maybe a better way would be to embed the html code that is used in the "File-Upload Process" right into your VB application. What that accomplished is 2 things. 1) The user wouldn't have to first navigate to the web-page in order to start the "File-Upload Process". 2) There may be a problem with trying to send input to the HTMLInputFileElement (This is the element that allows you to choose what file to upload). When your buddy allows posting of pictures again try the code above. It if doesn't work get ahold of me about embedding the html into your VB app. I'm positive it will work that way.

  14. #14

    Thread Starter
    Addicted Member
    Join Date
    Aug 2001
    Posts
    131
    Originally posted by Bloodeye
    Here ya go:

    Another option, and maybe a better way would be to embed the html code that is used in the "File-Upload Process" right into your VB application. What that accomplished is 2 things. 1) The user wouldn't have to first navigate to the web-page in order to start the "File-Upload Process". 2) There may be a problem with trying to send input to the HTMLInputFileElement (This is the element that allows you to choose what file to upload). When your buddy allows posting of pictures again try the code above. It if doesn't work get ahold of me about embedding the html into your VB app. I'm positive it will work that way.
    actually, i was going to have the webcontrol be hiddin, and whenver they click on the upload tab, the control goes to that page.. is there a better way?
    Last edited by Dr.Sparkle; Aug 7th, 2001 at 01:16 PM.

  15. #15
    Frenzied Member
    Join Date
    Mar 2001
    Location
    You are HERE •™
    Posts
    1,300
    One thing to think about, is if it's hidden how will they know that the file uploaded Ok?

    Here's what I would do. I would have it visible, and in the WebBrower control would be just the html for uploading the file. You could have it look exactly like how it is at the web-page. All the elements within would be operational. So up-loading a file would look and function just as though you were actually at the web-site. Plus the side benefit is the user would know when or if the file uploaded Ok.

    If you want I can help you out with that.

  16. #16
    Fanatic Member
    Join Date
    Sep 2000
    Location
    UK.
    Posts
    728

    Smile Suggestions...

    Originally posted by Dr. Sparkle
    ...inless you know of a way to get the result and parse the page without using the webcontrol then I will use it.
    Here is what i suggest.

    You could retrieve the PHP page using HTTP Protocol and a Winsock control.

    If you know the format of the PHP generated pages, then it will be easy to parse the information from them...

    Post back if help is needed.

    Laterz
    Digital-X-Treme
    Contact me on MSN Messenger: [email protected]

    [VBCODE]Debug.Print Round(((1097) - ((55 ^ 5 + 311 ^ 3 - 11 ^ 3) _
    / (68 ^ 5))) ^ (1 / 7), 13)[/VBCODE]

  17. #17

    Thread Starter
    Addicted Member
    Join Date
    Aug 2001
    Posts
    131

    Re: Suggestions...

    Originally posted by [Digital-X-Treme]


    Here is what i suggest.

    You could retrieve the PHP page using HTTP Protocol and a Winsock control.

    If you know the format of the PHP generated pages, then it will be easy to parse the information from them...

    Post back if help is needed.

    Laterz
    Well, I will know what teh generated structure will be once it's done. It will be whatever I want it to be. The problem is, I'm not writing the backend of it. Just the frontend for the proggy and the web. And the backend has not been writtin yet.. there has been a cople set-backs..

    I was thinking of having to php scripts.. one that outputs to hml for the web, and another for my programe.. the one for my programe would kinda be like XML in structure..

    kinda like

    Code:
    <pic>pic</pic>
             <name>blah</name>
             <email>email</email>
             <coment>Coment</coment>
    
    <pic>pic</pic>
             <name>blah</name>
             <email>email</email>
             <coment>Coment</coment>
    
    <pic>pic</pic>
             <name>blah</name>
             <email>email</email>
             <coment>Coment</coment>
    
    <pic>pic</pic>
             <name>blah</name>
             <email>email</email>
             <coment>Coment</coment>
    I was thinking of it out put like that, and some how parse that to add each item to a datagrid.. then letting them just doubleclick on the pic they want to preview and have it come up..


    anyway, bloodeye, when he puts it back up, i'll try that. Thanks..

    Is there no way to get into back on what the webbrowser control kinda like http of ftp has?

    (edit) I really need to spell check and ****..
    Last edited by Dr.Sparkle; Aug 7th, 2001 at 01:43 PM.

  18. #18

    Thread Starter
    Addicted Member
    Join Date
    Aug 2001
    Posts
    131
    Ok, I figured out the parsing now(well, someone else did for me).. So I will do it that way.. But I still can't figure out how to upload a file and send parms without the webcontrol.. argh..

    here is my parsing code..

    VB Code:
    1. Private Sub DoTagSearch(sText As String)
    2.     Dim nPos As Integer 'Holds where the "<" starts
    3.     Dim nClose As Integer 'Holds where the close tag "</" is found
    4.     Dim nTagEnd As Integer 'Holds where the ">" is found after npos
    5.     Dim bDone As Boolean 'Should this sub still search?
    6.     Dim sType As String 'Temporary place to hold the value
    7.     Dim sData As String 'Holds the data in the tag
    8.     bDone = True 'Yes, we should search
    9.     While bDone = True
    10.         nPos = InStr(nPos + 1, sText, "<", vbTextCompare) 'Find the next "<"
    11.         If nPos = 0 Then bDone = False ' If it didn't find anything, stop searching
    12.         If bDone = True Then 'make sure we are still searching
    13.             nTagEnd = InStr(nPos, sText, ">", vbTextCompare) 'find the ">" after the "<"
    14.             nClose = InStr(nTagEnd, sText, "</", vbTextCompare) ' look for the "</" after the last tag end
    15.             sType = Mid(sText, nPos + 1, nTagEnd - nPos - 1) 'Get the data between the "<" and the ">"
    16.             sData = Mid(sText, nTagEnd + 1, nClose - nTagEnd - 1) ' get the data between ">" and "</"
    17.             nPos = nClose + 1 'tell program to look from past the last "</"
    18.             AddResult sType, sData 'Add the result
    19.         End If
    20.     Wend
    21. End Sub
    22.  
    23. ------------------------------------------------------------------------------------------
    24. Private Sub AddResult(sType As String, sData As String)
    25.     If Trim(sData) = "" Then Exit Sub
    26.     Select Case UCase(sType)
    27.         Case "PIC": MsgBox "Found Picture: " & sData
    28.         Case "EMAIL": MsgBox "Found Email: " & sData
    29.         Case Else: MsgBox "Found " & sType & ": " & sData
    30.     End Select
    31. End Sub

    Later on I will add the true actions it takes when it gets the data, like add it to the grid..

  19. #19
    PowerPoster
    Join Date
    Jan 2001
    Location
    Florida
    Posts
    3,216
    hello I am trying to this code I got from Bloodeye a while ago. It used to work but I am trying to submit through a post method ona PHP page.

    I keep getting the error:

    "Object variable or with block variable not set"

    Any ideas what's up?

    Code:
    Private Sub Command1_Click()
        WebBrowser1.Navigate "http://www.alltheweb.com/add_url.php"
        
        
    End Sub
    
    Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
       
        Dim submitalltheweb As String, submittedalltheweb As String
        Static x As Integer
    
        submitalltheweb = "http://www.alltheweb.com/add_url.php"
        submittedalltheweb = Mid(WebBrowser1.LocationURL, 1, 29)
    
        If (pDisp = WebBrowser1.Object) Then
            If submittedalltheweb = "http://www.alltheweb.com/add_url.php" Then
                WebBrowser1.Navigate submitalltheweb
            ElseIf WebBrowser1.LocationURL = submitalltheweb Then
                With WebBrowser1.Document.Forms(1)
                    'If x > 9 Then Exit Sub
                    .All("url").Value = "www.test.com"
                    .All("submit").Click
                    'x = x + 1
                End With
            End If
        End If
        
    End Sub

  20. #20
    Frenzied Member
    Join Date
    Mar 2001
    Location
    You are HERE •™
    Posts
    1,300
    Hey Bud -

    What line is it highlighting when you get the error?

  21. #21
    PowerPoster
    Join Date
    Jan 2001
    Location
    Florida
    Posts
    3,216
    .All("url").Value = "www.test.com"

  22. #22
    Frenzied Member
    Join Date
    Mar 2001
    Location
    You are HERE •™
    Posts
    1,300
    This is just a guess:
    Check the name of the input text-box that you are trying to fill-in at http://www.alltheweb.com/add_url.php

    Look in the html code. The name maynot be "url"
    as it is in this line: .All("url").Value = "www.test.com"

  23. #23
    PowerPoster
    Join Date
    Jan 2001
    Location
    Florida
    Posts
    3,216
    it is I checked

    Code:
    <td align=left><input type=text value="http://" size=40 name=url></td>

  24. #24
    Frenzied Member
    Join Date
    Mar 2001
    Location
    You are HERE •™
    Posts
    1,300
    Ok....I see now. This page only has 1 form to fill-in.
    So try this:

    Code:
    With WebBrowser1.Document.Forms(0)
        'If x > 9 Then Exit Sub
        .All("url").Value = "www.test.com"
        .All("submit").Click
        'x = x + 1
    End With
    
    '//OR This:
    
    With WebBrowser1.Document
        'If x > 9 Then Exit Sub
        .All("url").Value = "www.test.com"
        .All("submit").Click
        'x = x + 1
    End With
    
    '//OR This
    
    With WebBrowser1.Document
        'If x > 9 Then Exit Sub
        .Forms(0).url.Value = "www.test.com"
        .Forms(0).submit.Click
        'x = x + 1
    End With
    One of those should work......if not I have a few more.

  25. #25
    PowerPoster
    Join Date
    Jan 2001
    Location
    Florida
    Posts
    3,216
    this is VERY interesting!!!!! All 3 of your examples actually submit the url BUT I still get the same error message as before but after the page has been submitted!


  26. #26
    Frenzied Member
    Join Date
    Mar 2001
    Location
    You are HERE •™
    Posts
    1,300
    The problem is the URL that you submit to: http://www.alltheweb.com/add_url.php

    Is the same URL as the page that is loaded after it's been submitted:
    http://www.alltheweb.com/add_url.php

    The easiest thing to do would be to add:
    On Error Resume Next to the WebBrowser1_DocumentComplete Event.

    If you wanted to do it by the book, then you would have to code a condition haveing it search the web-page "first" to see if there is an input text-box to add a value to.

  27. #27
    PowerPoster
    Join Date
    Jan 2001
    Location
    Florida
    Posts
    3,216
    yep that works
    thanks

  28. #28
    Frenzied Member
    Join Date
    Mar 2001
    Location
    You are HERE •™
    Posts
    1,300
    Dr.Sparkle -

    Here's the zip file....

  29. #29
    gr8tango
    Guest

    a little more info on code operation

    I'm also trying to upload a file via http using VB, and the code has been helpful (downloaded from Bloodeye, I think).

    I'm trying to send several files to an apache server running Perl, but I appear to be having some problems where the debugger stops at:

    Set docinputFile1 = doc.Forms(0).elements(0)

    I wasn't sure what references need to be set or other pointers may be necessary. Pls help.

    Thanks!

  30. #30
    Frenzied Member
    Join Date
    Mar 2001
    Location
    You are HERE •™
    Posts
    1,300
    All the references are already set within the project. It may be that you are using an old version of Internet Explorer? If that's the case try changing this in the Declarations.
    BTW: Are you having trouble running the project that you downloaded, or are you having problems adapting it to your html code?
    Code:
    Dim docinputText1 As HTMLInputTextElement
    to
    Dim docinputText1 As Object

  31. #31
    gr8tango
    Guest
    I'm using W2K, IE 5.0.x is that too old?

    The downloaded code appears to work, so my problem appears to be adapting it to my html code. I actually don't need to do this in HTML, but I thought it would be the easiest way. Would it be easier if I tried using a stright VB app?

    The exact error code is:
    Run-time error '91':
    Object variable or With block variable not set

    The debugger is pointing at the line:
    Set docinputFile1 = doc.Forms(0).elements(0)

    I tried the changes to 'object' which gives the same run-time error in the same place. I don't know the Perl back-end and my VB for html isn't too deep, so I was wondering if it's easier or safer to do VB only without the HTML? Any direction is appreciated.

    Thanks for your help!

  32. #32
    Frenzied Member
    Join Date
    Mar 2001
    Location
    You are HERE •™
    Posts
    1,300
    Without seeing your html code, I wouldn't be able to tell you what the problem is.
    It could be that Forms(0) is supposed to be Forms(1), or maybe there is a similar problem with the elements(0)...
    If you want, you can post your project and I'll take a look at it.

  33. #33
    gr8tango
    Guest
    Thanks!

    Okay, I found a typo and the Run-time 91 does not happen when experimenting with Bloodeye's modified script below (not actual URL). I guess the htmldoc was not created due to the typo, but I'm still not there yet...

    Private Sub htmlUpload()
    'This is all the html code for your Upload Page
    'I've reduced it to just the Upload html and modified it a little.
    uploadPage = "about:<html><head><style media=""screen"" type=""text/css"">"
    uploadPage = uploadPage & "body { font-size: 11px; font-family: Verdana, Arial }"
    uploadPage = uploadPage & "</style></head><body bgcolor=""#3f3f3f"" scroll=""no"" text=""gray""><center>"
    uploadPage = uploadPage & "<form name=""FilePost"" action=""http://myweburl.com/handler.cgi?username_entry=username&password_entry=pass&filesys=filesys"" method=""post"" enctype=""multipart/form-data"">"
    uploadPage = uploadPage & "<table border=""0"" cellpadding=""0"" cellspacing=""0"" width=""300""><tr><td width=""5"" bgcolor=""#434343""></td>"
    uploadPage = uploadPage & "<td bgcolor=""#868686"" class=""newstitile""><font size=""1"" color=""#e4e4e4"">&nbsp;</font></td>"
    uploadPage = uploadPage & "<td bgcolor=""#434343"" width=""5""></td></tr></table><table border=""0"" cellpadding=""0"" cellspacing=""0"" width=""300"" bgcolor=""#434343"">"
    uploadPage = uploadPage & "<tr><td width=""5""></td><td width=""300"" valign=""top""><font size=""1"">Select the file which you wish to upload: <br></font>"
    uploadPage = uploadPage & "<input type=""file"" name=""upfile"" size=""22""><font size=""1""><br>Name, email and a brief description of the file: </font>"
    uploadPage = uploadPage & "<input type=""text"" name=""description"" maxlength=""250"" size=""41""><br><font size=""1""><br></font>"
    uploadPage = uploadPage & "<table border=""0"" cellpadding=""0"" cellspacing=""0"" width=""100%""><tr><td><input type=""submit"" value=""Upload File""></td>"
    uploadPage = uploadPage & "<td></td><td><input type=""reset"" value=""Reset""></td></tr></table><br></form><center><font size=""1""> Temp Filler text.</font></center>"
    uploadPage = uploadPage & "<center><font size=""1"" color=""#afafaf""> Filler text for now</font></center></body></html>"
    WebBrowser1.Navigate uploadPage
    End Sub

    When I run the prog from inside VB6, the target webpage comes up, I can choose a file, and try to submit, but the file never gets through. My problem may be the authentication structure of the target page, but I'm not sure. The upload never happens, and I end up with my login page in the browser area of the VB program.

    I may need to attempt the upload in a non-password protected area to verify the general VB works as it originally did. My end goal is to have the VB prog use standard FSO to choose the file, then use HTTP post to upload it to a secure location. So, I guess I need help on:
    1. passing the file name(s) to the html document
    2. constructing the post to send the html document to the server
    3. making sure the client can send enough info to pass through authentication AND upload the file.

    The handler page (handler.cgi) if accessed directly simply has a form input, browse, and submit button. This web page works, and allows a web based upload of a file.

  34. #34
    Frenzied Member
    Join Date
    Mar 2001
    Location
    You are HERE •™
    Posts
    1,300
    I'll have to check it out later...Time to Sleep.
    Do you need to be logged in to upload?
    Do you have an upload page on the server?
    You know you could always just navigate to this page, and upload your files.

  35. #35
    Frenzied Member
    Join Date
    Mar 2001
    Location
    You are HERE •™
    Posts
    1,300
    Ok...Well, I'm not sure where your at right now.
    Sounds to me like you have the username/password (login) situation somewhat under control.
    As far as using FSO, I don't see the need. The user will be able to browser for the file to upload using the "<input=file>" element within the html.
    Maybe you have something else in mind?

    It's a little difficult for me to help without having an actual URL to work with.
    I understand your security concerns....Is there any way you can issue me a Username/Password combo so that we can get this working?
    Once it's working,then you can delete the Username/Password combo.

    The more I think about it, you might be better off using the Winsock Control.
    I say that for 2 reasons:
    1) The only way we would be able to pass the FSO File&Location to the "<input=file>" element in the html is by using copy& paste.
    That's because this element is deemed to be a security risk by MS.
    So there is no direct method of inputing a File&Location to this element without pasting it in.
    2) The username/password authentication issue.
    I'm not sure, we may be able to add a "usernameassword@" in the BeforeNavigate2 Event.
    The thing is Winsock would be better equipped to handle this.

  36. #36
    gr8tango
    Guest

    should I move this post?

    Bloodeye, I can't get the account changes yet, but I did find and modify some code below. The only problem is that the logon info doesn't take me to the correct page for the upload, so the upoad doesn't occur. When I use the correct URL, it takes me to the correct page.

    I'll see if I cant get you an account, but in the mean time, this example almost gets me there... and can benefit others.

    '******************* upload - begin
    'Upload file using input type=file
    Sub UploadFile(DestURL As String, FileName As String, _
    Optional ByVal FieldName As String = "File")
    Dim sFormData As String, d As String

    'Boundary of fields.
    'Be sure this string is Not In the source file
    Const Boundary As String = "---------------------------0123456789012"

    'Get source file As a string.
    sFormData = GetFile(FileName)

    'Build source form with file contents
    d = "--" + Boundary + vbCrLf
    d = d + "Content-Disposition: form-data; name=""" + FieldName + """;"
    d = d + " filename=""" + FileName + """" + vbCrLf
    d = d + "Content-Type: application/upload" + vbCrLf + vbCrLf
    d = d + sFormData
    d = d + vbCrLf + "--" + Boundary + "--" + vbCrLf

    'Post the data To the destination URL
    IEPostStringRequest DestURL, d, Boundary
    End Sub

    'sends URL encoded form data To the URL using IE
    Sub IEPostStringRequest(URL As String, FormData As String, Boundary As String)
    'Create InternetExplorer
    Dim WebBrowser: Set WebBrowser = CreateObject("InternetExplorer.Application")

    'You can uncoment Next line To see form results
    WebBrowser.Visible = True

    'Send the form data To URL As POST request
    Dim bFormData() As Byte
    ReDim bFormData(Len(FormData) - 1)
    bFormData = StrConv(FormData, vbFromUnicode)

    WebBrowser.Navigate URL, , , bFormData, _
    "Content-Type: multipart/form-data; boundary=" + Boundary + vbCrLf

    Do While WebBrowser.busy
    ' Sleep 100
    DoEvents
    Loop
    WebBrowser.Quit
    End Sub

    'read binary file As a string value
    Function GetFile(FileName As String) As String
    Dim FileContents() As Byte, FileNumber As Integer
    ReDim FileContents(FileLen(FileName) - 1)
    FileNumber = FreeFile
    Open FileName For Binary As FileNumber
    Get FileNumber, , FileContents
    Close FileNumber
    GetFile = StrConv(FileContents, vbUnicode)
    End Function
    '******************* upload - end

    Private Sub Form_Load()
    UploadFile "http://urlhandler.cgi?usr=name&pass=pass&info=filesave", "D:\Documents and Settings\qa1\Desktop\smplUploadFile.gif"
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width