Search code examples
c#stringurldotnet-httpclient

Replace parameters in URL parameter for HttpRequestMessage


How to replace a parameter in C# HttpRequestMessage URL?

I have the following code,

using (var request = new HttpRequestMessage(new HttpMethod("POST"), "http://MyService/Ids/63847/create"))

I want to replace 63847 with something like {0}, and have it set up dynamically. Is there a way to do that in C#?


Solution

  • using (var request = new HttpRequestMessage(
        new HttpMethod("POST"), 
        string.Format("http://MyService/Ids/{0}/create", 12345)
    ))