关于发送xml报文请求

JJYY0088 2016-03-23 03:20:39
发送请求报文 例子:
/****签到: <trn-b2e0001-rq> ****/
<?xml version="1.0" encoding="GB2312"?>
<bocb2e version="100" security="true" lang="chs">
<head>
<termid>E127000000001</termid>
<trnid>20060704001</trnid>
<custid>12345678</custid>
<cusopr>BOC</cusopr>
<trncod>b2e0001</trncod>
</head>
<trans>
<trn-b2e0001-rq>
<b2e0001-rq>
<custdt>20060704091000</custdt>
<oprpwd>88888888</oprpwd>
<ceitinfo>MIIE9AYJKoZIhvcNA……</ceitinfo>
</b2e0001-rq>
</trn-b2e0001-rq>
</trans>
</bocb2e>

请求响应报文
/****:签到响应<trn-b2e0001-rs>****/
<?xml version = "1.0" encoding = "GB2312"?>
<bocb2e version="100" security="true" lang="chs">
<head>
<termid>E127000000001</termid>
<trnid>20060704001</trnid>
<custid>12345678</custid>
<cusopr>BOC</cusopr>
<trncod>b2e0001</trncod>
<token>9TTQALYGH1</token>
</head>
<trans>
<trn-b2e0001-rs>
<status>
<rspcod>B001</rspcod>
<errmsg>OK</errmsg>
</status>
<serverdt>20020615102045</serverdt>
</trn-b2e0001-rs>
</trans>
</bocb2e>


ASP.NET 代码

/// <summary>
///
/// </summary>
/// <param name="xml">XML报文</param>
/// <param name="url">请求url</param>
/// <returns>返回响应的xml</returns>
public string PostXml(string xml, string url)
{
byte[] bytes = Encoding.UTF8.GetBytes(xml);

HttpWebRequest req = null;
try
{
//创建一个HttpWebRequest对象
req = (HttpWebRequest)HttpWebRequest.Create(url);

//设置它提交数据的方式post
req.Method = "POST";
//设置 Content-type HTTP 标头的值
req.ContentType = "text/xml";// "application/x-www-form-urlencoded;charset=GB2312";
req.ContentLength = bytes.Length;
req.KeepAlive = true;

using (Stream requestStream = req.GetRequestStream())
{
requestStream.Write(bytes, 0, bytes.Length);
}

HttpWebResponse res = (HttpWebResponse)req.GetResponse();
if (res.StatusCode != HttpStatusCode.OK)
{
string message = String.Format("POST failed. Received HTTP {0}", res.StatusCode);
return message;
}
else
{
StreamReader sr = new StreamReader(res.GetResponseStream(), Encoding.UTF8);
return sr.ReadToEnd();
}
}
catch (Exception ex)
{
return ex.Message;
}
}



失败了,返回错误信息 : The remote server returned an error: (500) Internal Server Error.

从代码来说,请问有什么问题?
...全文
623 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
Poopaye 2016-03-23
  • 打赏
  • 举报
回复
你应该去查服务器日志,而不是来问500是什么意思
  • 打赏
  • 举报
回复
意思就是服务器因为你的请求报错了,可能原因是你的数据格式、请求方式、请求参数任意一种或多种不符合参数要求,所以服务器主动返回500,当然还有种可能是服务器代码健壮度不够,你的参数导致程序出错了

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧