Solved

Visual Basic HTTPWebRequest - get Return Header Response

Posted on 2011-02-10
1
615 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
1 Comment
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 500 total points
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

728 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now