标签:style blog http io ar color os sp for
直接上码:
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。
标签:style blog http io ar color os sp for
原文地址:http://www.cnblogs.com/hiytom/p/4137104.html