为什么我收到“远程服务器返回错误:(500)内部服务器错误。” 这个错误是我的代码
public override object Request()
{
Response = "";
RequestTime = DateTime.Now;
var url = _service.Url;
HttpWebResponse responseObj = null;
try
{
Uri requestUri = null;
Uri.TryCreate(url, UriKind.Absolute, out requestUri);
CredentialCache cc = new CredentialCache();
NetworkCredential networkCredential = new NetworkCredential("username",
"password", url);
Uri uri = new Uri(url);
cc.Add(uri, "Basic", networkCredential);
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(uri);
request.Proxy = new WebProxy(url);
request.Credentials = cc;
request.Method = WebRequestMethods.Http.Post;
Response = request.GetResponse();
}
catch (Exception x)
{
Logger.append(x.Message, Logger.ERROR);
}
Duration = DateTime.Now.Subtract(RequestTime).TotalMilliseconds;
return Response;
}
我直接从浏览器尝试了网址,但它正在运行。
答案 0 :(得分:1)
如果您只是在浏览器中导航到该网址,则httpMethod将为GET
,但您在代码中将其设置为Post
。这可能就是它在浏览器中工作的原因,但不是你的代码。
我说你的代码可能没什么问题,但网站是否支持该网址的帖子?