错误500:SRVE0295E:报告错误:500-HttpWebResponse [英] Error 500: SRVE0295E: Error reported: 500 - HttpWebResponse
问题描述
我的任务是从IBM服务器下载附件. 问题是,当我使用C#-HttpWebRequest和HttpWebResponse进行请求时,总是得到状态码500和响应正文错误500:SRVE0295E:错误报告:500".但是,当我使用邮递员"执行相同的请求时,没有错误,并且文件已下载. 请注意以下事实,即需要一个代表当前会话的cookie.我向邮递员和我的请求添加了相同的cookie(可重复使用cookie).
my task is to download an attachment from an IBM server. The problem is that when I do the request with C# - HttpWebRequest and HttpWebResponse, I always get the status code 500 and the response body "Error 500: SRVE0295E: Error reported: 500". But!, when I do the same request with "Postman" there is no error and the file is downloaded. Please pay attention to the fact, that a cookie, which represents the current session, is needed. I added the same cookie (cookie can be reused) to Postman and to my request.
这是Postman的Http原始请求(我会发布一个屏幕截图,但缺乏信誉点):
Here is the Http raw request of Postman (I would have posted a screen shot but am lacking reputation points):
https://eforms. ebase.dlh.de:443/forms/secure/org/run/service/ContentStorageService44084
https://eforms.ebase.dlh.de:443/forms/secure/org/run/service/ContentStorageService44084
获取/forms/secure/org/run/service/ContentStorageService44084 HTTP/1.1 主机:eforms.ebase.dlh.de:443 Cookie:IPCZQX03e54bbd1d = 090038003914048a6f27dcb2bc9b9e0c3a6c63b0;路径=/; domain = dlh.de
GET /forms/secure/org/run/service/ContentStorageService44084 HTTP/1.1 Host: eforms.ebase.dlh.de:443 Cookie: IPCZQX03e54bbd1d=090038003914048a6f27dcb2bc9b9e0c3a6c63b0; path=/; domain=dlh.de
邮递员工作(这实际上是一个非常简单的GET请求,只有两个标头).
Postman works (it's really a very simple GET request with only two headers).
这是C#代码(向我返回错误500:SRVE0295E:报告错误:500")
And here is the C# code (which returns me the "Error 500: SRVE0295E: Error reported: 500")
HttpWebRequest req = null;
HttpWebResponse res = null;
req= (HttpWebRequest)WebRequest.Create("https://eforms.ebase.dlh.de:443/forms/secure/org/run/service/ContentStorageService44084");
req.Headers.Add("Cookie", "IPCZQX03e54bbd1d=090038003914048a6f27dcb2bc9b9e0c3a6c63b0; path=/; domain=dlh.de");
req.Host = "eforms.ebase.dlh.de";
req.Method = "GET";
try
{
res = (HttpWebResponse)req.GetResponse();
}
catch (WebException ex)
{
res = (HttpWebResponse) ex.Response;
}
Stream receiveStream = res.GetResponseStream();
StreamReader sr = new StreamReader (receiveStream, Encoding.UTF8);
string responseBody = sr.ReadToEnd();
Console.WriteLine((int)res.StatusCode + "\t" + res.StatusCode.ToString());
Console.WriteLine(responseBody);
任何提示都会非常感人.
Any hints will be very much apreciated.
PS:cookie可以,没有有效的cookie,我什至不会收到错误500:SRVE0295E:错误报告:500".因此错误消息来自IBM服务器,我可以肯定地说.
PS: the cookie is OK, without valid cookie I wouldn't even get the "Error 500: SRVE0295E: Error reported: 500". So the error message is from the IBM server, this I can tell for sure.
谢谢.
约翰·科瓦连科
推荐答案
好的,我找到了解决方案.我不得不假装自己是一个著名的浏览器. 因此,通过添加
OK, I found the solution. I had to pretend that I am a well-known browser. So by adding
req.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; Trident/7.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET4.0C; .NET4.0E)";
服务器将文件退还给我.
the server returned me the file.
这篇关于错误500:SRVE0295E:报告错误:500-HttpWebResponse的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!