zoukankan      html  css  js  c++  java
  • Post utf-8 请求

    /// <summary>
    /// POST请求与获取结果
    /// </summary>
    public static string HttpPost(string Url, string postDataStr)
    {
             //把数组转换成流中所需字节数组类型
                Encoding code = Encoding.GetEncoding("utf-8");
                byte[] bytesRequestData = code.GetBytes(postDataStr);
    
                //设置HttpWebRequest基本信息
                HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(Url);
                myReq.Method = "post";
                myReq.ContentType = "application/x-www-form-urlencoded";
    
                //填充POST数据
                myReq.ContentLength = bytesRequestData.Length;
                Stream requestStream = myReq.GetRequestStream();
                requestStream.Write(bytesRequestData, 0, bytesRequestData.Length);
                requestStream.Close();
    
                //发送POST数据请求服务器
                HttpWebResponse HttpWResp = (HttpWebResponse)myReq.GetResponse();
    
                //接收对应的流
                StreamReader reader = new StreamReader(HttpWResp.GetResponseStream());
                string retString = reader.ReadToEnd();
     
        return retString;
    }

    --调用

                var result = HttpPost(sendUrl, "id=1&text=" + "这是音频内容");
  • 相关阅读:
    Python Virtualenv的使用
    Pycharm常用的设置
    Zabbix学习目录
    DELL R740 Raid10与U盘启动项的配置
    Django
    Django
    Django
    Django
    Django
    Django
  • 原文地址:https://www.cnblogs.com/Hangle/p/6078200.html
Copyright © 2011-2022 走看看