码迷,mamicode.com
首页 > Windows程序 > 详细

C# 调用百度短链接api

时间:2014-12-02 13:31:06      阅读:768      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   io   ar   color   os   sp   for   

百度短链接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

标签:style   blog   http   io   ar   color   os   sp   for   

原文地址:http://www.cnblogs.com/hiytom/p/4137104.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!