Archived

This topic is now archived and is closed to further replies.

VB & HTTP & Websites

This topic is 5241 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all, is there a VB package, library, dll, source code, i can get to communicate with a PHP website and upload data, download data, not ftp, but like having the VB app fill a form, submit it and read in the results, then display them in a win32 gui, instead of a webpage. Im trying to make a small companion app that you can have in mem and that will check the website every 2m, for new stuff, etc... You should be able to partially navigate the website using that tool. Thanks for any insights into how to do this, any other questions, please post them,

[Hugo Ferreira][Positronic Dreams]
I Am Digerati.

Share this post


Link to post
Share on other sites
In VB go to the Project menu then References. Add Microsoft Internet Controls and Microsoft HTML Object Library.

Some example code

Dim IE As New InternetExplorer
Dim objDoc As HTMLDocument
Dim CharArray() As Byte
Dim sPost As String
Dim sHeader As String

sPost = "someinfo=1&someotherstuff=crap&somethingelse=456343"

'' need to convert string to byte array first or post wont work
ReDim CharArray(Len(sPost))
For i = 1 To Len(sPost)
CharArray(i - 1) = Asc(Mid$(sPost, i, 1))
Next i

sHeader = "Content-Type: application/x-www-form-urlencoded" + Chr(10) + Chr(13)
''navigate address, flags,forget,post info, header
''&H4 flag tells it not to read from cache
IE.Navigate "http://www.somesite.com/somepage.php", &H4 , , CharArray, sHeader

Do While IE.Busy = True
DoEvents
Loop

Do While IE.Document.ReadyState <> "complete"
DoEvents
Loop

Text1.Text = IE.Document.body.innerText

Share this post


Link to post
Share on other sites
WoW, thats great. I had played with that control before,
but I didn''t know the innerText thing...
Where did you find this? Very interesting...

Ok, i can picture myself sending/receiving small amounts
of data with this, by doing
.navigate "url?var=value&var2=value2"

...but imagine i want to upload a news story. I can''t just had the entire text to the url...
In these cases, what tricks do you use?

Thanks for the tip btw, very useful,

[Hugo Ferreira][Positronic Dreams]
I Am Digerati.

Share this post


Link to post
Share on other sites
Ok,
...if i have a form in the html page, a form named form1,
and a textbox in that form called alpha, can''t i just do:

IE.Document.body.form1.alpha = "whatever text i want"

and then submit the form?

...or, working by way of url encoding my data, where can i get
a good method of encoding chars into the url, i dont want to make a mistake and misrepresent the ã character as something else...

...or can we encode the data that our forms are passing in the header data? how to do this?

again, much thanx,

[Hugo Ferreira][Positronic Dreams]
I Am Digerati.

Share this post


Link to post
Share on other sites
Dim objForm As HTMLFormElement
Dim objElement As HTMLInputElement


For Each objForm In IE.Document.Forms
If objForm.Name = "form1" Then
For Each objElement In objForm
If objElement.Name = "alpha" Then
objElement.Value = "Some Value"
objElement.Click
End If
''you can also do this and check its type
''once you have all the form info filled in find the submit button and call click
If objElement.Type = "button" Then
objElement.Click
End If
Next
End If
Next

Share this post


Link to post
Share on other sites