locked
Analogy of a Stream and how it works RRS feed

  • Question

  • I'm trying to find either examples with explanation or at least direction: I've checked out MS' Technet to find info/explanations on a stream and I'm trying to wrap my head around it...to put it into an analogy: Is it essentially (setting the stage here) A highway where your request traffic is going one direction and your response traffic is going the other? In those defined directions they have a specific following of "vehicles" that set the method, the contentlength, and then write/send the information to the destination? So far if I am understanding it correctly (like that of ingress/egress of a network), my last question comes into play.
    If I have an application with 2 textboxes that I want to send to the destination -- where in my request method do I place this information?
    textbox1.text="Hello"
    textbox2.text="World"
    Dim request as httpwebrequest = httpwebrequest.create(http://www.somelamesite.org)
    
    With request
      .method="POST"
      .ContentType="application/x-www-form-urlencoded"
      .GetRequestStreams()
    
    End with
    

    For those that ask what am I trying to do -- I am trying to take information typed in text boxes to have them displayed on a website. If it sounds Hoky -- thats because it is.
    :)
    Thank you for any help or direction.
     
    • Edited by Plaethos Thursday, September 15, 2011 7:16 PM
    Thursday, September 15, 2011 7:10 PM

Answers

  • Hi Plaethos,

    Welcome to the MSDN Forum.

    To send the information, please take a look at the article: http://msdn.microsoft.com/en-us/library/d4cek6cc.aspx

    This code in that page can send your string message:

    ' Set the 'Method' property of the 'Webrequest' to 'POST'.
    myHttpWebRequest.Method = "POST"
    
    Console.WriteLine(ControlChars.Cr + "Please enter the data to be posted to the (http://www.contoso.com/codesnippets/next.asp) Uri :")
    ' Create a new string object to POST data to the Url.
    Dim postData As String = "textbox1=hello" + VBCrlf
    postData +="textbox2=world"
    Dim encoding As New ASCIIEncoding()
    Dim byte1 As Byte() = encoding.GetBytes(postData)
    ' Set the content type of the data being posted.
    myHttpWebRequest.ContentType = "application/x-www-form-urlencoded"
    ' Set the content length of the string being posted.
    myHttpWebRequest.ContentLength = byte1.Length
    Dim newStream As Stream = myHttpWebRequest.GetRequestStream()
    newStream.Write(byte1, 0, byte1.Length)
    Console.WriteLine("The value of 'ContentLength' property after sending the data is {0}", myHttpWebRequest.ContentLength)
    newStream.Close()
    
    
    
    
    

    At the receive side(the server side), you need to parse the two strings, and show it on a webpage. These operations should be finished by yourself, the stream cannot help you.

    I hope this will be helpful.

    Best regards,


    Mike Feng [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Plaethos Wednesday, September 21, 2011 4:30 PM
    Sunday, September 18, 2011 9:48 AM
    Moderator

All replies

  • Hi Plaethos,

    Welcome to the MSDN Forum.

    To send the information, please take a look at the article: http://msdn.microsoft.com/en-us/library/d4cek6cc.aspx

    This code in that page can send your string message:

    ' Set the 'Method' property of the 'Webrequest' to 'POST'.
    myHttpWebRequest.Method = "POST"
    
    Console.WriteLine(ControlChars.Cr + "Please enter the data to be posted to the (http://www.contoso.com/codesnippets/next.asp) Uri :")
    ' Create a new string object to POST data to the Url.
    Dim postData As String = "textbox1=hello" + VBCrlf
    postData +="textbox2=world"
    Dim encoding As New ASCIIEncoding()
    Dim byte1 As Byte() = encoding.GetBytes(postData)
    ' Set the content type of the data being posted.
    myHttpWebRequest.ContentType = "application/x-www-form-urlencoded"
    ' Set the content length of the string being posted.
    myHttpWebRequest.ContentLength = byte1.Length
    Dim newStream As Stream = myHttpWebRequest.GetRequestStream()
    newStream.Write(byte1, 0, byte1.Length)
    Console.WriteLine("The value of 'ContentLength' property after sending the data is {0}", myHttpWebRequest.ContentLength)
    newStream.Close()
    
    
    
    
    

    At the receive side(the server side), you need to parse the two strings, and show it on a webpage. These operations should be finished by yourself, the stream cannot help you.

    I hope this will be helpful.

    Best regards,


    Mike Feng [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Plaethos Wednesday, September 21, 2011 4:30 PM
    Sunday, September 18, 2011 9:48 AM
    Moderator
  • Thanks Mike.  I'll mark this as an answer.  :)

     

    Out of curiosity -- will this work for multiple posts such as that with an API?  I am having to do this for a java based API and as long as the field names are right, I have found this option works on an individual/per session basis.  Just wasn't sure on the multiple aspect - like when you you have a return of data from a queried DB. 


    The greatest mistakes made, are making none at all. I must be nearing Perfection then!
    Wednesday, September 21, 2011 4:26 PM