• 发送请求并返回


            public static string GetShortUrl(string url)
            {
                string paramstr = "{"url":"" + url + ""}";
                string api = "https://dwz.cn/admin/v2/create";
                Stream responseStream = null;
                StreamReader sr = null;
                Stream requestStream = null;
                string result = null;
                byte[] data = Encoding.UTF8.GetBytes(paramstr);
                try
                {
                    HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create(api);
                    httpRequest.ContentType = "application/json";
                    httpRequest.Method = "POST";
                    httpRequest.Headers.Add("Token", "a82e54954acb70c58a922ce9b2fe6fbd");
                    //发送数据
                    httpRequest.ContentLength = data.Length;
                    requestStream = httpRequest.GetRequestStream();
                    requestStream.Write(data, 0, data.Length);
                    requestStream.Flush();
                    //获取响应内容
                    HttpWebResponse HttpWResp = (HttpWebResponse)httpRequest.GetResponse();
                    responseStream = HttpWResp.GetResponseStream();
                    sr = new StreamReader(responseStream, Encoding.UTF8);
                    result = sr.ReadToEnd();
                }
                catch (Exception e)
                {
    
                }
                finally
                {
                    if (sr != null)
                        sr.Close();
                    if (responseStream != null)
                        responseStream.Close();
                    if (requestStream != null)
                        requestStream.Close();
                }
                if (!string.IsNullOrEmpty(result))
                {
                    LitJson.JsonData json = LitJson.JsonMapper.ToObject(result);
                    return json["ShortUrl"].ToString();
                }
                return url;
            }
    

      百度生成短链接  https://dwz.cn/console/apidoc?tdsourcetag=s_pctim_aiomsg

    111111
  • 相关阅读:
    BZOJ 4358 坑 莫队+线段树 死T
    BZOJ 4321 DP
    两倍问题
    通宵教室
    [编程题]字符串模式匹配
    [编程题]表达式求值
    [编程题]美团骑手包裹区间分组
    1153 Decode Registration Card of PAT
    1154 Vertex Coloring
    1155 Heap Paths
  • 原文地址:https://www.cnblogs.com/whl4835349/p/10384368.html
Copyright © 2020-2023  润新知