Skip to content

Replace obsolete WebRequest with HttpClient in trackback worker - #762

Merged
poppastring merged 3 commits into
mainfrom
copilot/update-webrequest-to-httpclient
Jan 17, 2026
Merged

poppastring merged 3 commits into
mainfrom
copilot/update-webrequest-to-httpclient

Conversation

Copilot AI commented Jan 17, 2026 •

Copy link
Copy Markdown
Contributor

The WebRequest.Create(Uri) API is obsolete in .NET and triggers SYSLIB0014 warnings during compilation.

Changes

  • Added static HttpClient instance with 30-second timeout to BlogDataServiceXml
  • Replaced WebRequest-based POST in TrackbackWorker with HttpClient.PostAsync()
  • Used ConfigureAwait(false) for async-over-sync pattern in worker thread context
// Before
WebRequest request = WebRequest.Create(new Uri(trackbackUrl));
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
using (StreamWriter requestWriter = new StreamWriter(request.GetRequestStream()))
{
    requestWriter.Write(trackbackMsg);
}
using (request.GetResponse()) { }

// After
using (var content = new StringContent(trackbackMsg, Encoding.UTF8, "application/x-www-form-urlencoded"))
{
    using (var response = httpClient.PostAsync(new Uri(trackbackUrl), content)
        .ConfigureAwait(false).GetAwaiter().GetResult())
    {
        response.EnsureSuccessStatusCode();
    }
}

The static HttpClient instance avoids socket exhaustion per Microsoft guidance. Functional behavior and error handling remain unchanged.

Original prompt

This section details on the original issue you should resolve

<issue_title>WebRequest is obsolete</issue_title>
<issue_description>WebRequest.Create(new Uri(trackbackUrl));

...\source\newtelligence.DasBlog.Runtime\BlogDataService.cs

'WebRequest.Create(Uri)' is obsolete: 'WebRequest, HttpWebRequest, ServicePoint, and WebClient are obsolete. Use HttpClient instead.'</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits January 17, 2026 19:17
Co-authored-by: poppastring <8739371+poppastring@users.noreply.github.com>
Co-authored-by: poppastring <8739371+poppastring@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix obsolete WebRequest usage in BlogDataService Replace obsolete WebRequest with HttpClient in trackback worker Jan 17, 2026
Copilot AI requested a review from poppastring January 17, 2026 19:23
@poppastring
poppastring marked this pull request as ready for review January 17, 2026 19:25
@poppastring
poppastring merged commit 1c38b75 into main Jan 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WebRequest is obsolete

2 participants