Runtime: HttpClient Uri Concat

Created on 24 Sep 2020  路  4Comments  路  Source: dotnet/runtime

.Net 5.0 RC1

I get an issue with HttpClient

I set my Base Address to https://xxx.zendesk.com/api/v2 and I post to ticket.json

So I wonder the request will post to https://xxx.zendesk.com/api/v2/ticket.json

But no. It post to https://xxx.zendesk.com/api/v2/ticket.json

So I tried ton set post to v2/ticket.json

In this case the request would be wrong: https://xxx.zendesk.com/api/v2/v2/ticket.json

But no it get correct: https://xxx.zendesk.com/api/v2/ticket.json

Code exemple here:

_http.BaseAddress = new Uri("https://xxx.zendesk.com/api/v2");
using HttpResponseMessage response = await _http.PostAsync("ticket.json", content);

Thi is not working neither

_http.BaseAddress = new Uri("https://xxx.zendesk.com/api/v2",UriKind.Absolute);
using HttpResponseMessage response = await _http.PostAsync(new Uri("ticket.json",UriKind.Relative), content);
area-System.Net.Http untriaged

All 4 comments

Have you tried https://xxx.zendesk.com/api/v2/ as your base address?

yes and it doesn't work

edit: my bad, I may have done something wrong.

https://xxx.zendesk.com/api/v2/ is working

Tagging subscribers to this area: @dotnet/ncl
See info in area-owners.md if you want to be subscribed.

This is intended behavior; as @campersau noted, that last "/" makes a big difference. See #29309 for more discussion on this.

Was this page helpful?
0 / 5 - 0 ratings