string responseBody = ""; HttpWebRequest request; try { var code = Encoding.UTF8; byte[] data = code.GetBytes(strPostdata); request = (HttpWebRequest)WebRequest.Create(new Uri(posturl)); request.UseDefaultCredentials = true; request.PreAuthenticate = true; request.Credentials = CredentialCache.DefaultCredentials; request.Method = "POST"; request.ContentType = "application/x-www-form-urlencoded"; request.ContentLength = data.Length; using (Stream requestStream = request.GetRequestStream()) { requestStream.Write(data, 0, data.Length); requestStream.Close(); } HttpWebResponse response = (HttpWebResponse)request.GetResponse(); StreamReader stream = new StreamReader(response.GetResponseStream(), System.Text.Encoding.UTF8); responseBody = stream.ReadToEnd(); stream.Close(); response.Close(); } catch (WebException ex) { responseBody = new StreamReader(ex.Response.GetResponseStream()).ReadToEnd(); }
在网上也找了几个post提交的方法 都有这个问题 但是使用http在线工具测试 没有这个问题
相关问题
- Generic Generics in Managed C++
- How to Debug/Register a Permanent WMI Event Which
- 'System.Threading.ThreadAbortException' in
- Bulk update SQL Server C#
- Should I use static function in c# where many call
确定是这个网址有问题还是所有的网址用这种方法都有问题。两个情况解决方法不一样的。
就是没有访问权限呗