Help in getting an http post from a website

alkhal4

New member
Joined
Jun 16, 2011
Messages
1
Programming Experience
1-3
Hello all

I am trying to get a post that comes from a webserver to a website, the post then is parsed and added to an sql server database. I am ok with the second part but my problem is with the first part.
The post comes in text format.


VB.NET:
The HTTP post that get sent looks as below

  X-Security-Data:1307806448479WBZ115511-2444-24441
  X-Security-Hash:4b28abdcdb2d00cbd3c6d103a37259bd
  User-Agent:ssef
  Host:localhost
  Content-Type:text/plain; charset=UTF-8
   
  date: Jun 11, 2011 3:34:03 PM GMT
  reference: REZ110611-2443-23227
  total: 124
I am using the code below to read the lines (I got the code from a forum and I am trying to modify it to fit my purpose.
VB.NET:
      Private TokensAndValues As SortedList(Of String, String) = Nothing
          Private Sub ReadAllTokensFromFile(ByVal FileLocation As String)
              Dim LinesInFile As List(Of String) = System.IO.File.ReadAllLines(FileLocation).ToList
              TokensAndValues = New SortedList(Of String, String)
              With TokensAndValues
                  .Add("date", String.Empty)
                  .Add("reference", String.Empty)
                  .Add("total", String.Empty)
              End With
              LinesInFile.ForEach(AddressOf CheckForTokens)
          End Sub
          Private Sub CheckForTokens(ByVal CurrentLine As String)
              For Each Token As String In TokensAndValues.Keys.ToList
                  If CurrentLine.ToLower.StartsWith(Token & ":") Then
                      TokensAndValues(Token) = CurrentLine.Remove(0, Token.Length + 1).Trim
                      Exit Sub 'Can be no more than 1 token on each line.
                  End If
              Next
          End Sub
          Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
              ReadAllTokensFromFile("C:\TestFile.txt")
              MessageBox.Show("phone: " & TokensAndValues("phone"))
              MessageBox.Show("date: " & TokensAndValues("date"))
          End Sub
My question is how do I capture the post from a webserver?
I don’t know what to use for “File location” to use in the above function

Is it possible to use something like the code below


VB.NET:
[/FONT]Dim Requester As HttpWebRequest = DirectCast(WebRequest.Create(Request.RawUrl), HttpWebRequest)

          With Requester
              .ContentType = "text/plain"
              .Method = "Get"

              .KeepAlive = True
          End With
          Dim WebResponse As HttpWebResponse = DirectCast(Requester.GetResponse(), HttpWebResponse)
          If WebResponse.StatusCode = HttpStatusCode.OK Then
              Dim readStream As New StreamReader(WebResponse.GetResponseStream(), True)
              readStream.ReadToEnd()
          End If
          WebResponse.Close()
But I am still not sure how to put both together. Could anyone help ?:confused:

I am not a professional programmer I am trying to learn how to do this to correct an error I have in my website

Thanks you
 

Latest posts

Back
Top