Asked by:
ERROR TO CONNECT WITH WEB API

Question
-
User-308236267 posted
Regards.
I am trying to invoke a web api from code, which I show below,
The problem is that my web browser uses proxy for safety reasons at work, so I read that I had to send it a Proxy object with the credentials that I use to be able to view the pages on the internet, I have tried it but I get an error.
I emphasize that when I am on a PC that does not use an internet proxy, I connect without problems with another code obviouslyDim credentials = New NetworkCredential("user", "password") Dim proxy = New WebProxy With { .Credentials = credentials} Dim handler = New HttpClientHandler With { .Proxy = proxy, .Credentials = credentials} Dim htp As New HttpClient(handler) htp.BaseAddress = New Uri("http://xxx.yyy.zzz.aaa:4857/swag/ui/") Dim consumeapi = htp.GetAsync("index") htp.DefaultRequestHeaders.Authorization = New AuthenticationHeaderValue("Bearer", "xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx") consumeapi.Wait() Dim readdata = consumeapi.Result
https://1drv.ms/u/s!AsQgQ_9eW2IkggWI2rkTxI05h1rY?e=vxMxgN
this code works without proxy
Dim htp As New HttpClient() htp.BaseAddress = New Uri("http://xxx.yyy.zzz.aaa:4857/swag/ui/") Dim consumeapi = htp.GetAsync("index") htp.DefaultRequestHeaders.Authorization = New AuthenticationHeaderValue("Bearer", "xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx") consumeapi.Wait() Dim readdata = consumeapi.Result
Saturday, August 15, 2020 4:05 PM
All replies
-
User1120430333 posted
Where is the interpreter since this is predominantly an English speaking forum concerning the error page posted?
Saturday, August 15, 2020 7:45 PM -
User-308236267 posted
Its a generic error say something like this
A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond xxx.yyy.zzzz:3453
Saturday, August 15, 2020 8:41 PM -
User-474980206 posted
You will need the proxy setting from the browser. Then use these settings (especially the proxy url) to fill in the proxy. Some corporate proxy servers require their own authentication.
Sunday, August 16, 2020 7:19 PM -
User-308236267 posted
Hi bruce, thanks for your answer
you have some code example where I can set these values?, especially the valu for the proxy you say?
Regards.
Sunday, August 16, 2020 8:17 PM -
User1686398519 posted
Hi Augusto C,
You only need to configure the same proxy settings in web.config according to the proxy settings of the browser.
You can click this link to see how to do it in web.config.
Best Regards,
YihuiSun
Friday, August 21, 2020 9:30 AM