您的位置:首页 > 理论基础 > 计算机网络

C#发送 http请求

2014-01-12 18:15 363 查看
string url = "http://php.weather.sina.com.cn/xml.php?city=" + HttpUtility.UrlEncode("遂宁", Encoding.GetEncoding("GB2312")) + "&password=DJOYnieT8234jlsK&day=0";

            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);

            req.Method = "Get";  //Get or Post

            req.ContentType = "application/x-www-form-urlencoded";

            
            HttpWebResponse rep = (HttpWebResponse)req.GetResponse();

//获取流

            using (Stream receiveStream = rep.GetResponseStream())

            {

               
            }

string url = "http://php.weather.sina.com.cn/xml.php?city=" + HttpUtility.UrlEncode("遂宁", Encoding.GetEncoding("GB2312")) + "&password=DJOYnieT8234jlsK&day=0";
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
req.Method = "Get";  //Get or Post
req.ContentType = "application/x-www-form-urlencoded";

HttpWebResponse rep = (HttpWebResponse)req.GetResponse();
//获取流
using (Stream receiveStream = rep.GetResponseStream())
{

}


string url = "http://www.fm418.com/UploadFile/book2013122311513570622.mp3";//url
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);//创建请求

req.Method = "Get";  //Get or Post

req.Accept = "application/json, text/javascript, */*; q=0.01";//请求信息
req.ContentType = "application/json; charset=UTF-8";

string param = "{id:" + txtId.Text + ",uid:" + txtUid.Text + "}"; //设置参数
using (Stream stream = req.GetRequestStream()) //把参数添加进去
{
byte[] buf = Encoding.UTF8.GetBytes(param);
stream.Write(buf, 0, buf.Length);
}

HttpWebResponse rep = (HttpWebResponse)req.GetResponse();   //返回对象
//获取流
using (Stream receiveStream = rep.GetResponseStream())
{

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: