HttpWebResponse远程服务器返回错误: (500) 内部服务器错误 的解决办法

例子:

 

myHttpWebRequest.Method = "POST";
Console.WriteLine ("/nPlease enter the data to be posted to the (http://www.contoso.com/codesnippets/next.asp) Uri :");

// Create a new string object to POST data to the Url.
string inputData = Console.ReadLine ();


string postData = "firstone=" + inputData;
ASCIIEncoding encoding = new ASCIIEncoding ();
byte[] byte1 = encoding.GetBytes (postData);

// Set the content type of the data being posted.
myHttpWebRequest.ContentType = "application/x-www-form-urlencoded";

// Set the content length of the string being posted.
myHttpWebRequest.ContentLength = byte1.Length;

Stream newStream = myHttpWebRequest.GetRequestStream ();

newStream.Write (byte1, 0, byte1.Length);
Console.WriteLine ("The value of 'ContentLength' property after sending the data is {0}", myHttpWebRequest.ContentLength);

// Close the Stream object.
newStream.Close ();

 

一般都是执行到 Stream newStream = myHttpWebRequest.GetRequestStream (); 的时候会抛出500 服务器错误,而且有时候会,有时候不会,本人试了很久才找到解决办法,

 

  原来是 myHttpWebRequest.ContentType = "application/x-www-form-urlencoded"; 这个的原因,改成

myHttpWebRequest.ContentType = "text/html"; 问题就解决了!汗!

 

阅读更多
换一批

远程服务器返回错误: (500) 内部服务器错误.

09-30

异常详细信息: System.Net.WebException: 远程服务器返回错误: (500) 内部服务器错误。rnrn源错误: rnrnrn行 99: oStreamOut.Close();rn行 100:rn[color=#FF0000]行 101: WebResponse myWebResponse = webrequest.GetResponse();[/color]rn行 102: Stream streamResponse = myWebResponse.GetResponseStream();rn行 103:rnrn[WebException: 远程服务器返回错误: (500) 内部服务器错误。]rn System.Net.HttpWebRequest.GetResponse() +5313773rn cba_hotell.GetRoomXml(String& requestStr) in e:\t.cnutg.com\Web.root\Web\Web\App_Code\Hotel_CBA\cba_hotel.cs:101rn cba_hotell.GetRoom1(Int32 hotelid, String begintime, String endtime) in e:\t.cnutg.com\Web.root\Web\Web\App_Code\Hotel_CBA\cba_hotel.cs:283rn HotelOld_CBAhotelview.GetView(Int32 hotelid) in e:\t.cnutg.com\Web.root\Web\Web\HotelOld\CBAhotelview.aspx.cs:78rn ASP.hotelold_cbahotelview_aspx.__DataBind__control15(Object sender, EventArgs e) in e:\t.cnutg.com\Web.root\Web\Web\HotelOld\CBAhotelview.aspx:139rn System.Web.UI.Control.OnDataBinding(EventArgs e) +99rn System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +92rn System.Web.UI.Control.DataBind() +15rn System.Web.UI.Control.DataBindChildren() +211rn System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +102rn System.Web.UI.Control.DataBind() +15rn System.Web.UI.Control.DataBindChildren() +211rn System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +102rn System.Web.UI.Control.DataBind() +15rn System.Web.UI.WebControls.GridView.CreateRow(Int32 rowIndex, Int32 dataSourceIndex, DataControlRowType rowType, DataControlRowState rowState, Boolean dataBind, Object dataItem, DataControlField[] fields, TableRowCollection rows, PagedDataSource pagedDataSource) +155rn System.Web.UI.WebControls.GridView.CreateChildControls(IEnumerable dataSource, Boolean dataBinding) +2417rn System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable data) +57rn System.Web.UI.WebControls.GridView.PerformDataBinding(IEnumerable data) +14rn System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data) +114rn System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +31rn System.Web.UI.WebControls.DataBoundControl.PerformSelect() +142rn System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +73rn System.Web.UI.WebControls.GridView.DataBind() +4rn HotelOld_CBAhotelview.GetHotelView() in e:\t.cnutg.com\Web.root\Web\Web\HotelOld\CBAhotelview.aspx.cs:35rn HotelOld_CBAhotelview.LinkButton3_Click(Object sender, EventArgs e) in e:\t.cnutg.com\Web.root\Web\Web\HotelOld\CBAhotelview.aspx.cs:139rn System.Web.UI.WebControls.LinkButton.OnClick(EventArgs e) +111rn System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument) +79rn System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10rn System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13rn System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +175rn System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565rn

远程服务器返回错误: (500) 内部服务器错误,

06-13

“/FreightSystemWeb”应用程序中的服务器错误。rnrn远程服务器返回错误: (500) 内部服务器错误。rnrn说明: 执行当前 Web 请求期间,出现未经处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 rnrn异常详细信息: System.Net.WebException: 远程服务器返回错误: (500) 内部服务器错误。rnrn源错误: rnrnrn行 8461: [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]rn行 8462: FreightSystemWeb.DataService.Admin.AddUserLogResponse FreightSystemWeb.DataService.Admin.AdminServiceSoap.AddUserLog(FreightSystemWeb.DataService.Admin.AddUserLogRequest request) rn行 8463: return base.Channel.AddUserLog(request);rn行 8464: rn行 8465: rnrn源文件: D:\DefaultCollection\RCS-Freight\FreightSystemWeb\Service References\DataService.Admin\Reference.cs 行: 8463 rnrn堆栈跟踪: rnrnrn[WebException: 远程服务器返回错误: (500) 内部服务器错误。]rn System.Net.HttpWebRequest.GetResponse() +6592536rn System.ServiceModel.Channels.HttpChannelRequest.WaitForReply(TimeSpan timeout) +55rnrn[ProtocolException: 响应消息的内容类型 text/html; charset=utf-8 与绑定(text/xml; charset=utf-8)的内容类型不匹配。如果使用自定义编码器,请确保正确实现 IsContentTypeSupported 方法。响应的前 1024 个字节为:“ rn rn rn IIS 7.5 详细错误 - 500.19 - Internal Server Error rn

没有更多推荐了,返回首页