webrequest-webresponse

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • CindyH

    #1

    webrequest-webresponse

    Hi

    I'm trying to use webrequest - webresponse to post a stream.
    I have set up a simple test with one aspx form holding the post code and
    trying to get another aspx form to receive the post on localhost.

    Can you explain to me the possible reasons why a 'GetResponse' - to send the
    data to a server might not be working for a simple text file with one line.

    test.text - contains: this is a test.

    (Using streamwriter to wrap the text in string and send as stream.
    so it looks like this "this is test".)

    Either the 'Getresponse' to send to server or the 'reader as streamreader =
    new streamreader(pa ge.request.inpu tstream)' is not working.

    From everything I have read and heard this should work.

    Thanks, CindyH



  • kimiraikkonen

    #2
    Re: webrequest-webresponse

    On Apr 29, 6:27 pm, "CindyH" <chensc...@new. rr.comwrote:
    Hi
    >
    I'm trying to use webrequest - webresponse to post a stream.
    I have set up a simple test with one aspx form holding the post code and
    trying to get another aspx form to receive the post on localhost.
    >
    Can you explain to me the possible reasons why a 'GetResponse' - to send the
    data to a server might not be working for a simple text file with one line..
    >
    test.text - contains: this is a test.
    >
    (Using streamwriter to wrap the text in string and send as stream.
    so it looks like this "this is test".)
    >
    Either the 'Getresponse' to send to server or the 'reader as streamreader =
    new streamreader(pa ge.request.inpu tstream)' is not working.
    >
    From everything I have read and heard this should work.
    >
    Thanks, CindyH
    Cindy,
    If you just want to upload a file to the server, you can also consider
    this using:

    Set credentials as you wish (username, password), destination path
    should be exact path including protocol prefix(eg: ftp://ftp.server.com/file..xml).

    Dim credential As New System.Net.Netw orkCredential(< username>,
    <password>)
    Dim web As New System.Net.WebC lient
    web.Credentials = credential
    web.UploadFile( "<destination_p ath>, <source_filepat h>)

    There also another functions such as uploadString, uploadData that you
    can use.

    Hoping it'll be useful,

    Onur Güzel

    Comment

    • Martin Honnen

      #3
      Re: webrequest-webresponse

      CindyH wrote:
      I'm trying to use webrequest - webresponse to post a stream.
      I have set up a simple test with one aspx form holding the post code and
      trying to get another aspx form to receive the post on localhost.
      >
      Can you explain to me the possible reasons why a 'GetResponse' - to send the
      data to a server might not be working for a simple text file with one line.
      Make sure you close the request stream before you try to process the
      response.
      If you still have problems then show us the exact code and exact error
      messages you get.

      --

      Martin Honnen --- MVP XML
      http://JavaScript.FAQTs.com/

      Comment

      • CindyH

        #4
        Re: webrequest-webresponse

        I have to use http xml post as that is what the client wants.



        "kimiraikko nen" <kimiraikkonen8 5@gmail.comwrot e in message
        news:d15e82d2-2673-4bbb-ba8c-360b8c29a3c6@27 g2000hsf.google groups.com...
        On Apr 29, 6:27 pm, "CindyH" <chensc...@new. rr.comwrote:
        Hi
        >
        I'm trying to use webrequest - webresponse to post a stream.
        I have set up a simple test with one aspx form holding the post code and
        trying to get another aspx form to receive the post on localhost.
        >
        Can you explain to me the possible reasons why a 'GetResponse' - to send
        the
        data to a server might not be working for a simple text file with one
        line.
        >
        test.text - contains: this is a test.
        >
        (Using streamwriter to wrap the text in string and send as stream.
        so it looks like this "this is test".)
        >
        Either the 'Getresponse' to send to server or the 'reader as streamreader
        =
        new streamreader(pa ge.request.inpu tstream)' is not working.
        >
        From everything I have read and heard this should work.
        >
        Thanks, CindyH
        Cindy,
        If you just want to upload a file to the server, you can also consider
        this using:

        Set credentials as you wish (username, password), destination path
        should be exact path including protocol prefix(eg:
        ftp://ftp.server.com/file.xml).

        Dim credential As New System.Net.Netw orkCredential(< username>,
        <password>)
        Dim web As New System.Net.WebC lient
        web.Credentials = credential
        web.UploadFile( "<destination_p ath>, <source_filepat h>)

        There also another functions such as uploadString, uploadData that you
        can use.

        Hoping it'll be useful,

        Onur Güzel


        Comment

        • CindyH

          #5
          Re: webrequest-webresponse

          Hi - hope someone can help with this - this code was working for a while in
          the 'real' code and then suddenly stopped - not sure what happen.
          I made two simple forms on localhost to try to test what is going on.
          I'm not getting any errors right now, but code is not working either - not
          reading the post in second form or else the first form is not sending it
          correctly.
          ---------------------------------------------------------------------------------------------------------------------------------------
          This is the Post.xml file I'm sending as stream (string), I have also tried
          just simple text file with one line and get same result:
          It looks like this when it comes out of the streamreader - before sending to
          other form

          "<?xml version="1.0"?>
          <userlist ACTION="newuser " VENDORNAME="som ename">
          <amouser AMOAID="101" AMOUSERNAME="Bi lly Jones" AMOAROLES="Stud ent"
          AMOAPRODUCTS="p roduct1,product 2" />
          </userlist>"

          ---------------------------------------------------------------------------------------------------------------
          This is code - in first form - sends the post to the second form:
          This code I've seen on internet in a number of places - all basically the
          same.

          Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
          System.EventArg s) Handles MyBase.Load
          Dim fileName As String =
          "C:\Inetpub\www root\AnnieGreen Springs\Post.xm l"
          Dim uri As String = "http://localhost/AnnieGreenSprin gs/testb.aspx"
          Dim req As System.net.WebR equest = Nothing
          Dim rsp As System.net.WebR esponse = Nothing
          Try
          req = System.Net.WebR equest.Create(u ri)
          req.Method = "POST"
          req.ContentType = "text/xml"
          Dim writer As System.IO.Strea mWriter = New
          System.IO.Strea mWriter(req.Get RequestStream() )
          writer.WriteLin e(GetTextFromXM LFile(fileName) )
          writer.Close()
          rsp = req.GetResponse
          Catch webex As System.Net.WebE xception
          Throw webex
          Catch Ex As System.Exceptio n
          Throw Ex
          Finally
          If req Is Nothing Then
          req.GetRequestS tream().Close()
          End If
          If rsp Is Nothing Then
          rsp.GetResponse Stream().Close( )
          End If
          End Try
          End Sub

          Private Function GetTextFromXMLF ile(ByVal file As String) As String
          Dim reader As New System.IO.Strea mReader(file)
          Dim ret As String = reader.ReadToEn d()
          reader.Close()
          Return ret
          End Function
          ------------------------------------------------------------------------------------------------------------------
          This is code in the second form that should read the post - instead I'm
          getting xmldata = "" - so it looks like it's not receiving post.

          Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
          System.EventArg s) Handles MyBase.Load
          Dim xmldata As String
          Response.Conten tType = "text/xml"
          Response.Clear( )
          Dim reader As StreamReader = New
          StreamReader(Pa ge.Request.Inpu tStream)
          xmldata = reader.ReadToEn d
          reader.Close()
          End Sub



          "Martin Honnen" <mahotrash@yaho o.dewrote in message
          news:eyfWRxhqIH A.1228@TK2MSFTN GP05.phx.gbl...
          CindyH wrote:
          >
          >I'm trying to use webrequest - webresponse to post a stream.
          >I have set up a simple test with one aspx form holding the post code and
          >trying to get another aspx form to receive the post on localhost.
          >>
          >Can you explain to me the possible reasons why a 'GetResponse' - to send
          >the
          >data to a server might not be working for a simple text file with one
          >line.
          >
          Make sure you close the request stream before you try to process the
          response.
          If you still have problems then show us the exact code and exact error
          messages you get.
          >
          --
          >
          Martin Honnen --- MVP XML
          http://JavaScript.FAQTs.com/

          Comment

          Working...