How do I get the content from an HTTPclient POST in VB.NET?

How do I get the content from an HTTPclient POST in VB.NET?

Here is what I have tried so for in my Winform Application.  In this example, I am trying to send 2 values, and I want to send the result to "responseString".
        Dim client As HttpClient = New HttpClient

        Dim values As New Dictionary(Of String, String) From {{"Input1", "hello"}, {"Input2", "world"}}
        Dim content As Object = New FormUrlEncodedContent(values)
        Dim response As Task(Of HttpResponseMessage) = client.PostAsync("", content)
        Dim responseString As String = response.Content.ReadAsStringAsync

Open in new window

I am currently getting my error at "response.content", probably becuase I am not sure how to handle a "Task(Of HttpResponseMessage)":
Dim responseString As String = response.Content.ReadAsStringAsync

Open in new window

BTW, the above code is what I cobbled together from websearches, but if I the amount of data expected is relatively small, perhaps it would be easier to come with a solution that isn't asynchronous?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

eeyoAuthor Commented:
I have also tried webclient as well, but no luck.  Here is the website form:
    <input name="Input1" type="text" id="MainContent_txtInput1" />
    <input name="Input2 type="text" id="MainContent_txtInput2 " />
    <input type="submit" name="ctl00$MainContent$Submit" value="Button" id="MainContent_Submit" />
    <span id="MainContent_lblNumber">Label</span>

Open in new window

Here is the code.  The responseInString text is the same.  Doesn't seem to be changed by the input1 or input2 values.
        Dim wb = New WebClient
        Dim data As New NameValueCollection()
        data("Input1") = "hello"
        data("Input2") = "world"
        Dim response = wb.UploadValues("http://localhost:64641/Default", "POST", data)
        Dim responseInString As String = Encoding.UTF8.GetString(response)
        txtResult.Text = responseInString

Open in new window

eeyoAuthor Commented:
I think I figured this out.  POST doesn't seem to interact direct with the HTML form inputs.  It looks you can use use arbitrary variables such as "Input1" and "Input2".  From ASP.NET website, you can access the "Input1" and "Input2" by using:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
    ..... Request.Form("Input2")
End Sub

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.