简体   繁体   中英

How to get response of GET request of web service and store it in a variable?

In my code I am sending a GET request to a server. In response of this I will get one URL which I want to store in a variable.

Can anyone help me regarding this? My code so far:

private void CreatePublicUrl()
{
    String CreatePublicUrl = String.Format("{0}/DataObjectServer/data/do/getproperties?cat=do&key=baseXmlPath&t={1}", base_url.Value, token);
    Debug.WriteLine("CreatePublicUrl==>" + CreatePublicUrl);
    HttpSyncRequest pub_url = new HttpSyncRequest();

    pub_url.sendGet(CreatePublicUrl, (urlResp) =>
    {
        var url = new Uri(urlResp);
        //      String urlresponse = JsonConvert.urlResp;
    });
}

It seem you're trying to achieve it using some proprietary library. You can achieve the same using HttpWebRequest and WebResponse .

You can also do it using WebClient class as follows

    WebClient client = new WebClient();
    String CreatePublicUrl = String.Format("{0}/DataObjectServer/data/do/getproperties?cat=do&key=baseXmlPath&t={1}", base_url.Value, token);
    using (Stream data = client.OpenRead(CreatePublicUrl))
    {
        using (StreamReader reader = new StreamReader(data))
        {
            string content = reader.ReadToEnd();
        }
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM