Post using HTTP
Post using HTTP
Post using HTTP
Post using HTTP
Post using HTTP
Post using HTTP Post using HTTP Post using HTTP Post using HTTP Post using HTTP Post using HTTP Post using HTTP Post using HTTP
Post using HTTP Post using HTTP
Post using HTTP
Go Back  Xtreme Visual Basic Talk > > > Post using HTTP


Reply
 
Thread Tools Display Modes
  #1  
Old 05-13-2010, 02:51 PM
whaaat whaaat is offline
Freshman
 
Join Date: Feb 2008
Posts: 48
Default Post using HTTP


I have a vb.net program running on a pc.

I have a vb.net asp.net website.

I want the pc program to send data to the website server.

I am looking at sample code that uses the POST method to my website. From the pc, I don't want the website to appear, just a post and the data is saved at the server to be used in the future.

The pc program is using this:
Code:
        Dim request As HttpWebRequest
        Dim response As HttpWebResponse = Nothing
        Dim reader As StreamReader
        Dim address As Uri

        Dim name As String ' FIRST field name variable to be posted
        Dim email As String ' SECOND field name variable to be posted
        Dim comments As String ' THIRD field name variable to be posted

        Dim data As StringBuilder
        Dim byteData() As Byte
        Dim postStream As Stream = Nothing

        'Specify the full url to the script.
        address = New Uri("http://www.mywebsite.com/")

        ' Create the web request 
        request = DirectCast(WebRequest.Create(address), HttpWebRequest)

        ' Set type to POST 
        request.Method = "POST"
        request.ContentType = "application/x-www-form-urlencoded"

        ' Create the data we want to send 
        name = "Hello " 'Here we put content into the first field variables

        data = New StringBuilder()
        'Notice the "name field" variable contained within quotes is also specified in double brackets
        data.Append("data=" + HttpUtility.UrlEncode("hello world"))
        data.Append("&user=" + HttpUtility.UrlEncode("new"))
        data.Append("&pass=" + HttpUtility.UrlEncode("test"))
        ' Create a byte array of the data we want to send 
        byteData = UTF8Encoding.UTF8.GetBytes(data.ToString())

        ' Set the content length in the request headers 
        request.ContentLength = byteData.Length

        ' Write data 
        Try
            postStream = request.GetRequestStream()
            postStream.Write(byteData, 0, byteData.Length)
        Finally
            If Not postStream Is Nothing Then postStream.Close()
        End Try
In my website, I have the Page_Load event with code to look at this data and save to a file on the server. I test this by typing into a web browser

Code:
http://www.mywebsite.com/?data=hello world&user=user&pass=pass
I am pretty sure that the Page_load event does not fire when I post from the pc vb.net program.

My question is "Is there an event that fires from my website so I can capture this data and save it to the server drive without the web page loading?"

Thanks.
Reply With Quote
  #2  
Old 05-17-2010, 11:23 AM
SteveNutt SteveNutt is offline
Freshman
 
Join Date: Jun 2005
Location: Thailand
Posts: 35
Default

Sounds like you need to do some debugging to find out how far upir VB program gets. You might also try this code...

Dim wreq As HttpWebRequest = DirectCast(WebRequest.Create(name & email & comments), HttpWebRequest)
wreq.Method = "GET"
Dim wresp As HttpWebResponse = DirectCast(wreq.GetResponse, HttpWebResponse)
__________________
IP Alarms - built with VB and ASP.net with a SQL Server back end.
Alarm Monitoring - built with ASP.Net web services.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Post using HTTP
Post using HTTP
Post using HTTP Post using HTTP
Post using HTTP
Post using HTTP
Post using HTTP Post using HTTP Post using HTTP Post using HTTP Post using HTTP Post using HTTP Post using HTTP
Post using HTTP
Post using HTTP
 
Post using HTTP
Post using HTTP
 
-->