using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Net; using System.IO; namespace TestCon { static class BillInfo { public static string BillInfo_Post_Get(string Post_String,string Post_Data) { try { string s_Connection_String = Post_String; HttpWebRequest BillInfo_Request = (HttpWebRequest)WebRequest.Create(s_Connection_String); BillInfo_Request.Method = "POST"; BillInfo_Request.ContentType = "application/x-www-form-urlencoded"; BillInfo_Request.ContentLength = s_Connection_String.Length; BillInfo_Request.Timeout = 20000; Stream BillInfo_Stream = BillInfo_Request.GetRequestStream(); BillInfo_Stream.Write(Encoding.UTF8.GetBytes(Post_Data), 0, Encoding.UTF8.GetBytes(Post_Data).Length); HttpWebResponse BillInfo_Response = (HttpWebResponse)BillInfo_Request.GetResponse(); StreamReader BillInfo_Reader = new StreamReader(BillInfo_Response.GetResponseStream(), Encoding.UTF8); return BillInfo_Reader.ReadToEnd(); } catch (System.Exception ex) { Console.WriteLine(ex); Console.ReadLine(); return ""; } } } }
解决方案
10
不要设置ContentLength
20
一致个屁,你写的长度和设置的长度方法用的都不一样
10
关键现在http协议规定必须有contentlength,所以就算你不设置,系统也会帮你加上,根本不需要关心这个