Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,587 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I'm learning HttpClient, and have made progress, but I'm getting
An invalid request URI was provided. The request URI must either be an absolute URI or BaseAddress must be set.
Here's my code, which works really well in VS2019, but not in ASP.NET web forms. It aborts when trying to invoke SendAsync.
HttpClient client = new HttpClient();
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", the_token);
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
client.Timeout = TimeSpan.FromSeconds(60);
var RequestString = ConfigurationManager.AppSettings["URIForSChedules"] + "?Key=" + wkey;
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, RequestString);
HttpResponseMessage responseResult = client.SendAsync(request).Result;
int status = (int)responseResult.StatusCode;
if (status != 200) { return "-1"; }
string responseBody = responseResult.Content.ReadAsStringAsync().Result;
HttpResponseMessage response = client.GetAsync(RequestString).Result;
response.EnsureSuccessStatusCode();
I tried using an absolute URI but it just complained louder. Is there something here that should be different?