(500) 内部服务器错误

xinxie 2007-03-16 02:48:25
string url = "http://localhost/t/login.aspx";
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
httpWebRequest.Method = "POST";
httpWebRequest.Timeout = 100000;
httpWebRequest.ContentType = "application/x-www-form-urlencoded";


Stream newStream = httpWebRequest.GetRequestStream ();

string postData = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"
+ "<s>\n"
+ "<t>\n"
+ "<user>" + txtID.Text + "</user>\n"
+ "<pass>" + txtPasswd.Text + "</pass>\n"
+ "</t>\n"
+ "</s>";

ASCIIEncoding encoding = new ASCIIEncoding();
byte[] inBuf = encoding.GetBytes(postData);
newStream.Write(inBuf, 0, inBuf.Length);
newStream.Close();

HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();

if (httpWebResponse.ContentLength>0)
{
Stream receiveStream = httpWebResponse.GetResponseStream();
StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8);
//通过readStream可以获得返回数据
string getData = readStream.ReadToEnd();
Response.Write(getData);

int p = getData.IndexOf ("<se>");
string se = "";
if (p > 0)
{
se = getData.Substring(p, getData.IndexOf("</se>") - p);
}
}
httpWebResponse.Close();

报错:
异常详细信息: System.Net.WebException: 远程服务器返回错误: (500) 内部服务器错误。

源错误:


行 73: newStream.Close();
行 74:
行 75: HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
行 76:
行 77: if (httpWebResponse.ContentLength>0)

...全文
355 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
xinxie 2007-03-16
  • 打赏
  • 举报
回复
请高手帮帮忙,头疼啊!
xinxie 2007-03-16
  • 打赏
  • 举报
回复
其实问题的关键在于xml数据流的传送与接收.我是想向login.aspx传送xml数据流,在login.aspx处理后返回xml数据流,可是不知该如何传送.
scow 2007-03-16
  • 打赏
  • 举报
回复
可能post的data不对,根据俺的经验,login页面一般是两个文本框,用"txtUserName=xxx&txtPassword=xxxx"试试,txtUserName和txtPassword是文本框的clientid
xinxie 2007-03-16
  • 打赏
  • 举报
回复
在线等
xinxie 2007-03-16
  • 打赏
  • 举报
回复
up
xinxie 2007-03-16
  • 打赏
  • 举报
回复
刚开始学,不会写,希望能告诉我怎么错了,不只是都要具体错误信息.
zhenjiaobing 2007-03-16
  • 打赏
  • 举报
回复
把你的IIS高级里面 取消 "显示友好http错误"
xinxie 2007-03-16
  • 打赏
  • 举报
回复
我想知道为什么错在哪里
Red_angelX 2007-03-16
  • 打赏
  • 举报
回复
web本身是否能正常访问?
还是你想获得具体的错误信息?

62,046

社区成员

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

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

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

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