Link to home
Start Free TrialLog in
Avatar of bizantd
bizantdFlag for Australia

asked on

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()
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

If you are not using the http: protocol, what protocol are you using?
Avatar of bizantd

ASKER

I am using Http protocol.
System.Uri needs to know the protocol, so does this work?

Dim serverAddress = "http://someip:customport"
Avatar of bizantd

ASKER

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.
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.
ASKER CERTIFIED SOLUTION
Avatar of bizantd
bizantd
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Is ServerAddressUri a Uri or string variable?
Avatar of bizantd

ASKER

Its a URI and gives me same result as if I was using without http.
Are you constructing the Uri the same as here:

client.BaseAddress = New Uri(serverAddress)
Avatar of bizantd

ASKER

yes I am.
That doesn't make any sense, but oh well :D
Avatar of bizantd

ASKER

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