How to make an HTTP get request with parameters

后端 未结 5 2245
故里飘歌
故里飘歌 2020-12-02 12:59

Is it possible to pass parameters with an HTTP get request? If so, how should I then do it? I have found an HTTP post requst (link). In that exampl

5条回答
  •  我在风中等你
    2020-12-02 13:35

    First WebClient is easier to use; GET arguments are specified on the query-string - the only trick is to remember to escape any values:

            string address = string.Format(
                "http://foobar/somepage?arg1={0}&arg2={1}",
                Uri.EscapeDataString("escape me"),
                Uri.EscapeDataString("& me !!"));
            string text;
            using (WebClient client = new WebClient())
            {
                text = client.DownloadString(address);
            }
    

提交回复
热议问题