我一直在尝试发送 Web 请求,但我遇到了这个错误“远程服务器返回错误:(500)内部服务器错误。” 在 req.GetResponse() 上;
我真的不知道是否缺少某些东西或是否有问题。
任何人都可以帮助我吗?
string soap = "<?xml version='1.0'?> " +
"soapenv:Envelope xmlns:ns='http://www.buzonfiscal.com/ns/xsd/bf/bfcorp/32' xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'> " +
"<soapenv:Header/> " +
"<soapenv:Body> " +
"<ns:RequestCancelaCFDi uuid='" + this.txtUUID.Text + "' rfcReceptor='" + this.txtReceptor.Text + "' rfcEmisor='" + this.txtEmisor.Text + "'/> " +
"</soapenv:Body> " +
"</soapenv:Envelope> ";
X509Certificate2 cert = new X509Certificate2(@"C:\test.pfx", "password");
HttpWebRequest req = (HttpWebRequest)WebRequest.Create("https://WebRequest.com/bfcorpcfdi32ws");
req.ContentType = "text/xml";
req.Method = "POST";
req.ClientCertificates.Add(cert);
// MessageBox.Show(soap);
using (Stream stm = req.GetRequestStream())
{
using (StreamWriter stmw = new StreamWriter(stm))
{
stmw.Write(soap);
stmw.Close();
}
}
WebResponse response = req.GetResponse();
Stream responseStream = response.GetResponseStream();
response = req.GetResponse();
StreamReader sr = new StreamReader(response.GetResponseStream());
string result = sr.ReadToEnd();
sr.Close();