C# POST提交数据302错误求解【NET正常CORE302错误】测试环境NET 5.0
我用NET 4.8正常的代码但换成NET CORE就302错误了。
测试了两个组件 都是一样的错误【HttpClient和HttpWebRequest】
原来NET正常的
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(strPostUrl);
req.ServicePoint.Expect100Continue = false;
req.Host = PostHost;
req.KeepAlive = true;
req.Proxy = null;//
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded;charset=" + charset;
Stream streamReq = req.GetRequestStream();
streamReq.Write(bytPost, 0, bytPost.Length);
streamReq.Flush();
HttpWebResponse res = (HttpWebResponse)req.GetResponse();
换HttpClient测试代码
HttpContent content = new StringContent(strPostData, Encoding.UTF8);
content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/x-www-form-urlencoded" );
HttpResponseMessage hrm = hc.PostAsync(strPostUrl, content).Result;
hrm.EnsureSuccessStatusCode();
ResponseText = hrm.Content.ReadAsStringAsync().Result;
ResponseAbsoluteUri = hrm.RequestMessage.RequestUri.AbsoluteUri;
发现CORE的测试结果一样的错误。NET FRAMEWORK是正常运行的。
求解。感谢