Solved

Visual Basic HTTPWebRequest - get Return Header Response

Posted on 2011-02-10
1
618 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
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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C# Single Form 8 42
Prevent call a sub/function several times when data bind to gridview 21 29
VB.net Open Folder in Windows Explorer 3 29
vb.net and creating a class 5 17
Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

809 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