发送jsonconvert.serializeobject时,Httpwebrequst返回500内部服务器错误 [英] Httpwebrequst returns 500 internal server error while sending jsonconvert.serializeobject
本文介绍了发送jsonconvert.serializeobject时,Httpwebrequst返回500内部服务器错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我们发送
JsonConvert.SerializeObject(lstobject);
到这里的网址 lstobject 是发送到url.error的大型列表,也会在3分钟后返回,以便记录错误,使webrequest等待5分钟
to the url here lstobject is large list sent to the url.error also returned after 3 minutes to log error hoew to make webrequest to wait 5 minutes
var httpWebRequest = (HttpWebRequest)WebRequest.Create(ConfigurationManager.AppSettings["JsonPayloadPostUrl"].ToString());
httpWebRequest.Timeout = 1000000;
httpWebRequest.Method = "POST";
using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
{
streamWriter.Write(jsonPayload);
}
var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
var responseText = streamReader.ReadToEnd();
}
我的尝试:
我们添加了
What I have tried:
we added
httpWebRequest.Timeout = 1000000;
但没有用,请建议一些解决方案。使请求完成
but no use please suggest some solution.to make the request completed
推荐答案
你好
如果你使用web api ,这是因为你在控制器中使用了多个功能。
转到项目中的App_Start文件夹,转到WebApiConfig.cs并替换
api / {controller} / {action} / {id}而不是
api / {controller} / {id}
前面的
:routeTemplate
希望它有效
Hello
if you are using web api, it is because you are using more than one function in your controller.
go to App_Start folder in your project, go to WebApiConfig.cs and replace
"api/{controller}/{action}/{id}" instead of
"api/{controller}/{id}"
in front of : routeTemplate
hope it works
这篇关于发送jsonconvert.serializeobject时,Httpwebrequst返回500内部服务器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文