夜间模式暗黑模式
字体
阴影
滤镜
圆角
主题色
C# 实现 Post

引用

using System.Text;
using System.Net;
using System.IO;

方法

public string Post(string encoding,string uristring ,string data)
        {
            Encoding myEncoding = Encoding.GetEncoding(encoding);
            /*
             选择编码页
             编码表参考:EncodingInfo.CodePage那篇文章
            */
            byte[] myByte = myEncoding.GetBytes(data);//数据转码

            string responseResult = string.Empty;//储存结果
            HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(uristring);//实例化
            req.Method = "POST";
            req.ContentType = "application/json";
//如果传入 key=value&key=value 格式,这里填写 application/x-www-from-urlencoded
            req.ContentLength = myByte.Length;

            req.GetRequestStream().Write(myByte, 0, myByte.Length);//写入请求
            HttpWebResponse myRespond = (HttpWebResponse)req.GetResponse();//接收结果
            if (myRespond != null && myRespond.StatusCode == HttpStatusCode.OK)
            {
                StreamReader sr = new StreamReader(myRespond.GetResponseStream());
                responseResult = sr.ReadToEnd();
                sr.Close();
            }
            myRespond.Close();
            return responseResult;
        }
暂无评论

发送评论 编辑评论


				
上一篇
下一篇