C # 1 request data mode

 

 

 

public  static  string PostWebRequest2 ()
        {
            REQ the HttpWebRequest = (the HttpWebRequest) HttpWebRequest.Create ( " http://183.66.231.18:8184/api/services/app/ChildSystem/checkLogin " ); // This is the url you want to submit 
            Encoding encoding = Encoding.UTF8;

            IDictionary<string, string> para = new Dictionary<string, string>();
            para.Add("ticket", "22d0a6a46bbdf44ec718f600b012b261");
          
            Buffer the StringBuilder = new new the StringBuilder (); // data which is to be submitted 
            int I = 0 ;

            foreach (string key in para.Keys)
            {
                if (i > 0)
                {
                    buffer.AppendFormat("&{0}={1}", key, para[key]);
                }
                else
                {
                    buffer.AppendFormat("{0}={1}", key, para[key]);
                }
                i++;
            }

            byte[] bs = Encoding.UTF8.GetBytes(buffer.ToString());//UTF-8
            string responseData = String.Empty;
            req.Method = "POST";
            req.ContentType = "application/x-www-form-urlencoded;charset=utf-8";
            req.ContentLength = bs.Length;
            using (Stream reqStream = req.GetRequestStream())
            {
                reqStream.Write(bs, 0, bs.Length);
                reqStream.Close();
            }
            using (HttpWebResponse response = (HttpWebResponse)req.GetResponse())
            {
                using (StreamReader reader = new StreamReader(response.GetResponseStream(), encoding))
                {
                    responseData = reader.ReadToEnd().ToString();
                    return responseData;
                }
            }
        }

 

Postman corresponding interface

 

Guess you like

Origin www.cnblogs.com/guxingy/p/11891142.html