VB.NET Post REST HTTP request without http in baseaddress

I have vb.net api which requires to connect to HOST with out using http.For example its using serverbase address="someipwithout http".

I am getting this error:{"Invalid URI: The URI scheme is not valid."}

However if I use wfetech it works fine.

My Code is as follow

Dim serverAddress = "someip:customport"
Dim URI As String = "/some uri"

Dim client As New HttpClient(handler)
client.BaseAddress = New Uri(serverAddress)
client.DefaultRequestHeaders.Accept.Add(New MediaTypeWithQualityHeaderValue("application/xml"))
Dim response = client.PostAsXmlAsync(URI, x).Result()
bizantdEngineerAsked:
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.

Bob LearnedCommented:
If you are not using the http: protocol, what protocol are you using?
0
bizantdEngineerAuthor Commented:
I am using Http protocol.
0
Bob LearnedCommented:
System.Uri needs to know the protocol, so does this work?

Dim serverAddress = "http://someip:customport"
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

bizantdEngineerAuthor Commented:
Hi Bob
Syntactically it works but.I am also using wfetch to validate the response from the server.
If I use Dim serverAddress="www.microsoft.com" its giving the error but in wfetch it works fine on http
and this is same what I want to achieve.
0
Bob LearnedCommented:
Well, that is a conundrum, since you can't use System.Uri without a protocol, and I believe that you need System.Uri here:

client.BaseAddress = New Uri(serverAddress)

Open in new window


You would need to find a different approach that doesn't require a Uri.
0
bizantdEngineerAuthor Commented:
Hi Bob

I worked it out by using

Dim GRequest = DirectCast(WebRequest.Create(ServerAddressUri), HttpWebRequest)
0

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
Bob LearnedCommented:
Is ServerAddressUri a Uri or string variable?
0
bizantdEngineerAuthor Commented:
Its a URI and gives me same result as if I was using without http.
0
Bob LearnedCommented:
Are you constructing the Uri the same as here:

client.BaseAddress = New Uri(serverAddress)
0
bizantdEngineerAuthor Commented:
yes I am.
0
Bob LearnedCommented:
That doesn't make any sense, but oh well :D
0
bizantdEngineerAuthor Commented:
Dim GRequest = DirectCast(WebRequest.Create(ServerAddressUri), HttpWebRequest)
0
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
Web Applications

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.