HttpWebResponse状态StatusCode = InternalServerError

summervibeGua 2017-09-01 10:34:50
网上找了好久也没解决
protected void btnAssetData_Click(object sender, EventArgs e)
{
string url = "http://10.1.51.11:8080/eam/queryGJService_preAssets.app";
AssetDataRequest post = new AssetDataRequest();
Item postitem = new Item();

post.page = 1;
post.pageSize = 10;
post.items = postitem;

postitem.startCreateTime = "2015-01-01";
postitem.endCreateTime = "2017-08-01";

string postData = CreatDataJson(post);

//try
//{
IoCContainer.Get<ISyncAssetDataSvc>().SyncAssetData(url, postData);
divMessage.ShowMessageInfo("同步成功");
//}
//catch (Exception ex)
//{
// divMessage.ShowMessageError(ex.Message);
//}
}

public void SyncAssetData(string url, string postData)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "POST";
request.ContentType = "application/json";
request.Timeout = 20 * 60 * 1000;

StreamWriter streamWriter = new StreamWriter(request.GetRequestStream(), Encoding.GetEncoding("UTF-8"));
streamWriter.Write(postData);
streamWriter.Close();

HttpWebResponse response;
try
{
response = (HttpWebResponse)request.GetResponse();
}
catch (WebException ex)
{
response = (HttpWebResponse)ex.Response;
}

Stream responseStream = response.GetResponseStream();
StreamReader responseStreamReader = new StreamReader(responseStream, Encoding.GetEncoding("UTF-8"));
string responseResult = responseStreamReader.ReadToEnd();
}
...全文
1185 23 打赏 收藏 转发到动态 举报
写回复
用AI写文章
23 条回复
切换为时间正序
请发表友善的回复…
发表回复
ilikeff8 2017-09-01
  • 打赏
  • 举报
回复
另外,queryGJService_preAssets.app是什么
ilikeff8 2017-09-01
  • 打赏
  • 举报
回复
不是调用的问题,是你要调用的方法内部有问题,或者是方法找不到需要重启IIS
summervibeGua 2017-09-01
  • 打赏
  • 举报
回复
引用 12 楼 xdashewan 的回复:
[quote=引用 11 楼 jianwei7517 的回复:] 调试返回信息就是InternalServerError,服务器繁忙
断点调试?不是让你看个结果[/quote] 调试看哪部分的信息,到response这边就出错了
xdashewan 2017-09-01
  • 打赏
  • 举报
回复
引用 11 楼 jianwei7517 的回复:
调试返回信息就是InternalServerError,服务器繁忙
断点调试?不是让你看个结果
summervibeGua 2017-09-01
  • 打赏
  • 举报
回复
引用 10 楼 xdashewan 的回复:
[quote=引用 9 楼 jianwei7517 的回复:] 请问调试服务器端是去抓包数据吗,没有调试过
和抓包没有关系,直接用你本地调试,不是直接让你在服务器调试[/quote] 调试返回信息就是InternalServerError,服务器繁忙
xdashewan 2017-09-01
  • 打赏
  • 举报
回复
引用 9 楼 jianwei7517 的回复:
请问调试服务器端是去抓包数据吗,没有调试过
和抓包没有关系,直接用你本地调试,不是直接让你在服务器调试
summervibeGua 2017-09-01
  • 打赏
  • 举报
回复
引用 6 楼 xdashewan 的回复:
[quote=引用 5 楼 jianwei7517 的回复:] 现在无从下手了,不知道哪里修改调试
调试服务端你调用的那个接口[/quote] 请问调试服务器端是去抓包数据吗,没有调试过
summervibeGua 2017-09-01
  • 打赏
  • 举报
回复
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>错误提示</title> <script type="text/javascript"> function ref() { var url = window.location.href; if (url.indexOf("?") == -1) { url += "?cacheModel=true"; } else { url += "&cacheModel=true"; } window.location.href = url; } </script> </head> <body> <center><h1>服务器繁忙,请稍候再试......</h1></center> <center><button onclick="ref();">刷新页面</button></center> <div style="display:none;"></div> </body> </html>
  • 打赏
  • 举报
回复
调试服务器端。不要在客户端打转转。
xdashewan 2017-09-01
  • 打赏
  • 举报
回复
引用 5 楼 jianwei7517 的回复:
现在无从下手了,不知道哪里修改调试
调试服务端你调用的那个接口
summervibeGua 2017-09-01
  • 打赏
  • 举报
回复
现在无从下手了,不知道哪里修改调试
xdashewan 2017-09-01
  • 打赏
  • 举报
回复
500错误有可能是服务器的bug导致
summervibeGua 2017-09-01
  • 打赏
  • 举报
回复
response = (HttpWebResponse)request.GetResponse();时会出错。报远程服务器返回错误: (500) 内部服务器错误。 加了try catch后,response 信息 StatusCode = InternalServerError
summervibeGua 2017-09-01
  • 打赏
  • 举报
回复
等一个海尔破
summervibeGua 2017-09-01
  • 打赏
  • 举报
回复
summervibeGua 2017-09-01
  • 打赏
  • 举报
回复
问题解决了,谢谢大家,整个人都变好了
xdashewan 2017-09-01
  • 打赏
  • 举报
回复
引用 21 楼 jianwei7517 的回复:
报500的话和request有关系吗
和你传入的参数可能有关,但错肯定是服务端报的
summervibeGua 2017-09-01
  • 打赏
  • 举报
回复
引用 20 楼 xdashewan 的回复:
[quote=引用 19 楼 jianwei7517 的回复:] 但是测试接口是没问题的啊
及时传参不同也不应该出500错误吧[/quote] 报500的话和request有关系吗
xdashewan 2017-09-01
  • 打赏
  • 举报
回复
引用 19 楼 jianwei7517 的回复:
但是测试接口是没问题的啊
及时传参不同也不应该出500错误吧
summervibeGua 2017-09-01
  • 打赏
  • 举报
回复
引用 16 楼 hanjun0612 的回复:
500错误应该是对方服务器内部异常的问题
但是测试接口是没问题的啊
加载更多回复(3)

110,567

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

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