• ASP.NET Post方式提交


    public static string SendMsg(string fxPhone, string fxPassword, string toPhone, string msg)
            {
                try
                {
                    string url = "u=" + fxPhone + "&";
                    url = url + "p=";
                    url = url + fxPassword + "&";
                    url = url + "to=";
                    url = url + toPhone + "&";
                    url = url + "m=" + msg;
    
                    string formUrl = "http://quanapi.sinaapp.com/fetion.php";
                    string formData = url;                               //提交的参数
    
                    //注意提交的编码 这边是需要改变的 这边默认的是Default:系统当前编码
                    byte[] postData = Encoding.UTF8.GetBytes(formData);
    
                    // 设置提交的相关参数 
                    HttpWebRequest request = WebRequest.Create(formUrl) as HttpWebRequest;
                    Encoding myEncoding = Encoding.UTF8;
                    request.Method = "POST";
                    request.KeepAlive = false;
                    request.AllowAutoRedirect = true;
                    request.ContentType = "application/x-www-form-urlencoded";
                    request.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727; .NET CLR  3.0.04506.648; .NET CLR 3.5.21022; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)";
                    request.ContentLength = postData.Length;
    
                    // 提交请求数据 
                    System.IO.Stream outputStream = request.GetRequestStream();
                    outputStream.Write(postData, 0, postData.Length);
                    outputStream.Close();
    
                    HttpWebResponse response;
                    Stream responseStream;
                    StreamReader reader;
                    string srcString;
                    response = request.GetResponse() as HttpWebResponse;
                    responseStream = response.GetResponseStream();
                    reader = new System.IO.StreamReader(responseStream, Encoding.GetEncoding("UTF-8"));
                    srcString = reader.ReadToEnd();
                    string result = srcString;   //返回值赋值
                    reader.Close();
                    return result;
                }
                catch
                {
                    return "error";
                }
            }
  • 相关阅读:
    团队作业4--项目冲刺
    第七篇Scrum冲刺博客--Interesting-Corps
    第六篇Scrum冲刺博客--Interesting-Corps
    第五篇Scrum冲刺博客--Interesting-Corps
    第四篇Scrum冲刺博客--Interesting-Corps
    第三篇Scrum冲刺博客--Interesting-Corps
    第二篇Scrum冲刺博客--Interesting-Corps
    团队作业6——复审与事后分析
    alpha阶段项目复审
    团队作业5—测试与发布说明
  • 原文地址:https://www.cnblogs.com/kylin2016/p/5848734.html
Copyright © 2020-2023  润新知