Solved

vb post data to web site

Posted on 2006-06-24
5
216 Views
Last Modified: 2008-01-09
Hello
I am using VB Express 2005 and would like ideas of how to automatically post data to a website.
I want to create an application which will periodically send it's results to a public web server over https so that it can be analysed. VB Express 2005 includes a Web Browser control if this helps.
My intention is to use the VB app to compress a file of results and then post that file to an appropriate server.
Any ideas?
Thanks
0
Comment
Question by:john_123
  • 2
5 Comments
 
LVL 35

Expert Comment

by:[ fanpages ]
ID: 16977982
Hi,

Speak to the owner of the server & ask how they can receive your file, or the contents of your file.

You may be able to post the entire file using a HTTP:// request, or you may need to stream the contents line by line (or character by character) to a pre-built data channel.

BFN,

fp.

0
 
LVL 1

Author Comment

by:john_123
ID: 16978943
Hi
We are the owner of the server.
We need to periodically transfer an amount of statistical data to a web server for analysis.
Rather than writing a client/server to transfer data I thought it would be appopriate to simply post the data to the web server. This way I can also use HTTPS to encrypt it later.

I have gone down this path so far
 
Dim xmlhttp As Object
xmlhttp = CreateObject("MSXML2.ServerXMLHTTP")
xmlhttp.Open("POST", "http://website.com/update.php", False)
xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
xmlhttp.send("probe_id=2&stuff=2")
MsgBox(xmlhttp.ResponseText)
xmlhttp = Nothing

This only seems to allow me to send data separated by the & sign as part of the URL - I would like to use this to be able to submit a file.

Is there any better way to achieve this?
0
 
LVL 1

Author Comment

by:john_123
ID: 16979853
I think I have achieved my goal through the following...

  Dim strText As String, strBody As String
        Dim strFilename As String
        strFilename = "c:\results.txt"

        Microsoft.VisualBasic.FileOpen(1, strFilename, OpenMode.Binary, OpenAccess.Read)
        strText = New String(" ", LOF(1))
        Microsoft.VisualBasic.FileGet(1, strText)
        Microsoft.VisualBasic.FileClose(1)

        Dim xmlhttp As Object
        xmlhttp = CreateObject("MSXML2.ServerXMLHTTP")
        xmlhttp.Open("POST", "http://www.website.com/update.php", False)
        xmlhttp.setRequestHeader("Content-Type", "multipart/form-data, boundary=AaB03x")
        strBody = _
           "--AaB03x" & vbCrLf & _
           "Content-Disposition: form-data; name=""probe_id""" & vbCrLf & vbCrLf & _
           "12345" & vbCrLf & _
           "--AaB03x" & vbCrLf & _
           "Content-Disposition: attachment; name=""FILE1""; filename=""" & strFilename & """" & vbCrLf & _
           "Content-Type: text/plain" & vbCrLf & vbCrLf & _
           strText & vbCrLf & _
           "--AaB03x"
        xmlhttp.send(System.Text.Encoding.Default.GetBytes(strBody))
        MsgBox(xmlhttp.ResponseText)
        xmlhttp = Nothing
0
 
LVL 5

Accepted Solution

by:
Netminder earned 0 total points
ID: 17164456
Closed, 500 points refunded.
Netminder
Site Admin
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now