Solved

Visual Basic HTTPWebRequest - get Return Header Response

Posted on 2011-02-10
1
622 Views
Last Modified: 2012-05-11
I am trying to get the response code from the following code:  It should return a 204 response, but how do I get the response code?

        Dim myReq As HttpWebRequest = DirectCast(WebRequest.Create(Urlstr), HttpWebRequest)
        myReq.Method = "POST"
        myReq.ContentType = "application/json; charset=utf-8"
        Dim bytes As Byte()
        bytes = Encoding.UTF8.GetBytes(myInspection)
        Dim mylogin As String
        myloginDetails = myUserName & ":" & myPassword
        mylogin = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(myloginDetails))
        myReq.Headers.Add(HttpRequestHeader.Authorization, mylogin)
        objRequestStream = myReq.GetRequestStream()

        objRequestStream.Write(bytes, 0, bytes.Length)
        objRequestStream.Close()

Open in new window

0
Comment
Question by:keith1001
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 500 total points
ID: 34865638
After you've written to the request stream, you need to issue the request and get the HttpWebResponse back which you do like:
Dim response As HttpWebResponse = CType(request.GetResponse(), HttpWebResponse)
Dim status As HttpStatusCode = response.StatusCode

Open in new window

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question