C# 调用百度短链接api

百度短链接api

直接上码:

public static string PostDataGetHtml(string postDataStr)
        {
            string Url = "http://dwz.cn/create.php";
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url);
            request.Method = "POST";
            request.ContentType = "application/x-www-form-urlencoded";
            request.ContentLength = postDataStr.Length;
            Stream myRequestStream = request.GetRequestStream();
            StreamWriter myStreamWriter = new StreamWriter(myRequestStream, Encoding.GetEncoding("gb2312"));
            myStreamWriter.Write(postDataStr);
            myStreamWriter.Close();
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            Stream myResponseStream = response.GetResponseStream();
            StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("utf-8"));
            string retString = myStreamReader.ReadToEnd();
            myStreamReader.Close();
            myResponseStream.Close();
            return retString;
        }

//调用
PostDataGetHtml("url="+postDataStr);

会得到返回的json 并转化成string。

 

C# 调用百度短链接api

上一篇:WIN7下查看DirectX版本方法


下一篇:windows7+eclipse+hadoop2.5.2环境配置