• POST GET 请求示例


    HTTP GET 请求代码:

    HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.baidu.com/");
    HttpWebResponse response = (HttpWebResponse)request.GetResponse();
    Stream receiveStream = response.GetResponseStream();
    StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8);
    string responseData = readStream.ReadToEnd();
    response.Close();
    readStream.Close();
    Response.Write(responseData);

    HTTP POST请求代码:

    HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.webxml.com.cn/WebServices/WeatherWebService.asmx/getSupportCity");
    string data = "byProvinceName=河北";
    byte[] bs = Encoding.UTF8.GetBytes(data);
    string responseData;
    request.Method = "POST";
    request.ContentLength = bs.Length;
    request.ContentType = "application/x-www-form-urlencoded";
    using (Stream reqStream = request.GetRequestStream())
    {
    
        reqStream.Write(bs, 0, bs.Length);
        reqStream.Close();
    }
    
    using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
    {
        using (StreamReader readStream = new StreamReader(response.GetResponseStream(), Encoding.UTF8))
        {
            responseData = readStream.ReadToEnd().ToString();
            readStream.Close();
        }
        response.Close();
    }
    Response.Write(responseData);
  • 相关阅读:
    tableView的高度问题
    信任机型
    cell 内部 设置width 总不对
    图文混排
    UICollectionview实现自定义cell的移动删除
    ios 各种技术
    打包ane之后在FB上生成ipa的阶段错误
    自动布局出代码植入 的图像化实例
    MapReduce编程实例
    二叉树的遍历(递归遍历、非递归遍历、层序遍历)
  • 原文地址:https://www.cnblogs.com/AngelLee2009/p/3540757.html
Copyright © 2020-2023  润新知