Exemple #1
0
        public async Task <string> Do0Shorten(string longUrl)
        {
            string link = string.Empty;

            Dictionary <string, string> values = new Dictionary <string, string>
            {
                { "link", longUrl }
            };

            FormUrlEncodedContent content = new FormUrlEncodedContent(values);

            HttpResponseMessage response = await client.PostAsync("https://do0.ir/post/SJAj4Ik6Q9Rd/2.5", content);

            string responseString = await response.Content.ReadAsStringAsync();

            Do0Data root = JsonConvert.DeserializeObject <Do0Data>(responseString);

            if (root.success)
            {
                link = "https://do0.ir/" + root.@short;
            }
            else
            {
                Growl.Error(root.error);
            }

            return(link);
        }
Exemple #2
0
        public static string Do0Shorten(string longUrl)
        {
            string link = string.Empty;

            using (WebClient wb = new WebClient())
            {
                NameValueCollection data = new NameValueCollection
                {
                    ["link"] = longUrl
                };
                byte[] response         = wb.UploadValues("https://do0.ir/post/SJAj4Ik6Q9Rd/2.5", "POST", data);
                string responseInString = Encoding.UTF8.GetString(response);

                Do0Data root = JsonConvert.DeserializeObject <Do0Data>(responseInString);

                if (root.success)
                {
                    link = root.@short;
                }
                else
                {
                    Console.WriteLine(root.error);
                }
            }

            return("https://do0.ir/" + link);
        }