[C #] using C # Http read the Post data

Private String Post (String NUM) 
        { 

            Encoding myEncoding = Encoding.GetEncoding ( "GB2312"); // Select coded character set 
            string data = "customerSn = 6fea75ba52gf339f & phone =" + num + "& cate = fuzhu & channel = hui-5"; // page data system (field name = value, connected by ampersands) to be uploaded to 
            byte [] bytesToPost = System.Text.Encoding.Default.GetBytes (data ); // convert data bytes 

            string responseResult = String.Empty ; 
            the HttpWebRequest REQ = (the HttpWebRequest) HttpWebRequest.Create ( "http://95.163.204.90:2121/api/account/black.json"); // create a valid httprequest request, address and port, and must specify the path and web page systems engineer confirm correct, or communication has been unsuccessful 
            req.Method = "POST"; 
            req.ContentType = "the Application / the X--the WWW-form-urlencoded;charset=gb2312";
            = bytesToPost.Length req.ContentLength; 
            }

            using (Stream reqStream = req.GetRequestStream())
            { 
                ReqStream.Write (bytesToPost, 0, bytesToPost.Length); // the system to upload page data sent through POST 
            } 
            the HttpWebResponse cnblogsRespone = (the HttpWebResponse) req.GetResponse (); 
            ! IF (= cnblogsRespone = null && cnblogsRespone.StatusCode HttpStatusCode.OK =) 
            { 
                the StreamReader SR; 
                the using (the StreamReader new new SR = (cnblogsRespone.GetResponseStream ())) 
                { 
                    ResponseResult sr.ReadToEnd = (); // the return value of the web page format json system, in ResponseResult, the specific content is web page with your system engineer in charge of the protocol number of the return value of the agreement 
                } 
                sr.Close (); 
            cnblogsRespone.Close (); 
            return ResponseResult;
        }

  测试:Post("18868511332"); 返回:{"status":0,"msg":"ok","data":"18868511332"}

 

Reference Address: https://www.cnblogs.com/da3j/p/10178627.html

Guess you like

Origin www.cnblogs.com/mqxs/p/11330041.html