[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 397
  • Last Modified:

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()
0
bizantd
Asked:
bizantd
  • 6
  • 6
1 Solution
 
Bob LearnedCommented:
If you are not using the http: protocol, what protocol are you using?
0
 
bizantdAuthor 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
bizantdAuthor 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
 
bizantdAuthor Commented:
Hi Bob

I worked it out by using

Dim GRequest = DirectCast(WebRequest.Create(ServerAddressUri), HttpWebRequest)
0
 
Bob LearnedCommented:
Is ServerAddressUri a Uri or string variable?
0
 
bizantdAuthor 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
 
bizantdAuthor Commented:
yes I am.
0
 
Bob LearnedCommented:
That doesn't make any sense, but oh well :D
0
 
bizantdAuthor Commented:
Dim GRequest = DirectCast(WebRequest.Create(ServerAddressUri), HttpWebRequest)
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 6
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now