bizantd
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.DefaultRequestHeade rs.Accept. Add(New MediaTypeWithQualityHeader Value("app lication/x ml"))
Dim response = client.PostAsXmlAsync(URI, x).Result()
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.DefaultRequestHeade
Dim response = client.PostAsXmlAsync(URI,
If you are not using the http: protocol, what protocol are you using?
ASKER
I am using Http protocol.
System.Uri needs to know the protocol, so does this work?
Dim serverAddress = "http://someip:customport"
Dim serverAddress = "http://someip:customport"
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.
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:
You would need to find a different approach that doesn't require a Uri.
client.BaseAddress = New Uri(serverAddress)
You would need to find a different approach that doesn't require a Uri.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Is ServerAddressUri a Uri or string variable?
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)
client.BaseAddress = New Uri(serverAddress)
ASKER
yes I am.
That doesn't make any sense, but oh well :D
ASKER
Dim GRequest = DirectCast(WebRequest.Crea te(ServerA ddressUri) , HttpWebRequest)