System.Net.HttpWebRequest equivalent

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

    System.Net.HttpWebRequest equivalent

    Hi

    What is the System.Net.Http WebRequest equivalent code for the MS XML related
    code below?

    Thanks

    Regards


    Set oHttpPost = CreateObject("M icrosoft.XMLHTT P")
    oHttpPost.Open "POST", "www.MyUrl.com" , False
    oHttpPost.setRe questHeader "Content-Type",
    "applicatio n/x-www-form-urlencoded"

    POSTData = "<data here>"

    oHttpPost.Send (POSTData)

    If (oHttpPost.stat us >= 200 And oHttpPost.statu s < 300) Then
    St = oHttpPost.respo nseText
    End If



  • Martin Honnen

    #2
    Re: System.Net.Http WebRequest equivalent

    John wrote:
    What is the System.Net.Http WebRequest equivalent code for the MS XML related
    code below?
    Set oHttpPost = CreateObject("M icrosoft.XMLHTT P")
    oHttpPost.Open "POST", "www.MyUrl.com" , False
    oHttpPost.setRe questHeader "Content-Type",
    "applicatio n/x-www-form-urlencoded"
    >
    POSTData = "<data here>"
    >
    oHttpPost.Send (POSTData)
    >
    If (oHttpPost.stat us >= 200 And oHttpPost.statu s < 300) Then
    St = oHttpPost.respo nseText
    End If
    Check out WebClient and its methods
    WebClient client = new WebClient();
    string st = client.UploadSt ring("http://example.com/page.aspx",
    "<data here>");

    --

    Martin Honnen --- MVP XML

    Comment

    • Martin Honnen

      #3
      Re: System.Net.Http WebRequest equivalent

      Martin Honnen wrote:
      Check out WebClient and its methods
      WebClient client = new WebClient();
      Add
      client.Headers. Add("Content-Type",
      "applicatio n/x-www-form-urlencoded");
      here
      string st = client.UploadSt ring("http://example.com/page.aspx", "<data
      here>");


      --

      Martin Honnen --- MVP XML

      Comment

      • John

        #4
        Re: System.Net.Http WebRequest equivalent

        Hi

        Many thanks. Have been reading on WebCLient but can't figure what replaces
        oHttpPost.statu s and oHttpPost.respo nseText. Have googled to but couldn't
        find an equivalent example.

        Thanks again.

        Regards


        "Martin Honnen" <mahotrash@yaho o.dewrote in message
        news:OMX7YkDiIH A.4744@TK2MSFTN GP06.phx.gbl...
        John wrote:
        >
        >What is the System.Net.Http WebRequest equivalent code for the MS XML
        >related
        >code below?
        >
        >Set oHttpPost = CreateObject("M icrosoft.XMLHTT P")
        >oHttpPost.Op en "POST", "www.MyUrl.com" , False
        >oHttpPost.setR equestHeader "Content-Type",
        >"applicatio n/x-www-form-urlencoded"
        >>
        >POSTData = "<data here>"
        >>
        >oHttpPost.Se nd (POSTData)
        >>
        >If (oHttpPost.stat us >= 200 And oHttpPost.statu s < 300) Then
        > St = oHttpPost.respo nseText
        >End If
        >
        Check out WebClient and its methods
        WebClient client = new WebClient();
        string st = client.UploadSt ring("http://example.com/page.aspx", "<data
        here>");
        >
        --
        >
        Martin Honnen --- MVP XML
        http://JavaScript.FAQTs.com/

        Comment

        • Anthony Jones

          #5
          Re: System.Net.Http WebRequest equivalent

          "John" <info@nospam.in fovis.co.ukwrot e in message
          news:eyJIP0DiIH A.4536@TK2MSFTN GP06.phx.gbl...
          Hi
          >
          Many thanks. Have been reading on WebClient but can't figure what replaces
          oHttpPost.statu s and oHttpPost.respo nseText. Have googled to but couldn't
          find an equivalent example.
          >

          The responseText is the return value of a call such as UploadString().

          The status isn't directly available however if a status representing a
          problem in 400 or 500 range is received the call will throw a WebException.

          If you need further details you can interogate the execption's properties.
          For example
          ((HttpWebRespon se)e.Response). StatusCode would get you the status code
          returned by the server.



          --
          Anthony Jones - MVP ASP/ASP.NET


          Comment

          Working...