Solved

vb post data to web site

Posted on 2006-06-24
5
226 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code 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 …
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

735 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