0
https://www.stote.it/bais/%ID%

I have a URL like the above and a method that takes key. I want to replace ID with key and make a get request. I can make the get request if I manually replace ID with a value, but I want to do it in code. Any help?

private String getEmailTemplate(string key)
{
    string html = string.Empty;

    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
    using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
    using (Stream stream = response.GetResponseStream())
    using (StreamReader reader = new StreamReader(stream))
    {
        html = reader.ReadToEnd();
    }

    return html;
2
  • 2
    url = url.Replace("%ID%", key);? Commented May 8, 2017 at 22:47
  • will give it a try and get back thanks anyway for the prompt response Commented May 8, 2017 at 22:49

1 Answer 1

3

If url is arbitrary, make it https://www.stote.it/bais/{0} and use String.Format(url, key).

This way if you ever add more arguments, there is no complicated string replacement.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.