zoukankan      html  css  js  c++  java
  • POST提交方式

    一.RestSharp(需要引入RestSharp.dll 文件)

       

       /       // <summary>
                 /// </summary>
            /// <param name="uploadData">x</param>
            /// <param name="strFlag"></param>
            public void Upload(string uploadData,string upload_IP)
            {
                try
                {
                    var client = new RestSharp.RestClient(upload_IP);
               
                    var requesPost = new RestRequest("", Method.POST);
    
                     requesPost.AddParameter("application/x-www-form-urlencoded", uploadData, ParameterType.RequestBody);
                    IRestResponse responsePost = client.Execute(requesPost);
                    var responseContent = responsePost.Content;
    
               
                }
                catch (Exception ex)
                {
                    
                }
            }

    二.

      /// <summary>
     ///上传的格式为json字符串
            /// </summary>
            /// <param name="postUrl">请求地址</param>
            /// <param name="paramData">入参</param>
            /// <param name="dataEncode">编码方式</param>
            /// <returns></returns>
            public string PostWebRequest(string postUrl, string paramData, Encoding dataEncode)
            {
                string ret = string.Empty;
                try
                {
                    byte[] byteArray = dataEncode.GetBytes(paramData); //转化
                    HttpWebRequest webReq = (HttpWebRequest)WebRequest.Create(new Uri(postUrl));
                    webReq.Method = "POST";
                    webReq.ContentType = "application/json";
    
                    webReq.ContentLength = byteArray.Length;
                    Stream newStream = webReq.GetRequestStream();
                    newStream.Write(byteArray, 0, byteArray.Length);//写入参数
                    newStream.Close();
                    HttpWebResponse response = (HttpWebResponse)webReq.GetResponse();
                    StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
                    ret = sr.ReadToEnd();
                    sr.Close();
                    response.Close();
                    newStream.Close();
                }
                catch (Exception ex)
                {
                    MessageBoxs.ShowError(ex.Message);
                }
                return ret;
            }
  • 相关阅读:
    Eclipse中的快捷键
    Eclipse配置
    Java语言概述
    视口及媒体查询
    弹性盒flex
    less——css预处理语言
    过渡/动画/变形
    列表/表格/表单
    渐变
    背景background
  • 原文地址:https://www.cnblogs.com/mengzhixingping/p/10839496.html
Copyright © 2011-2022 走看看