URL 在浏览器中工作,但使用 HttpWebRequest 从控制台应用程序返回 500
尝试访问 Web 服务 URL,可以通过浏览器进行简单的 GET 操作(按预期返回状态代码 200),没有问题,但通过控制台应用程序执行时,它返回状态代码 500?我怀疑这是代理或 DNS 问题,但不确定...
这是从控制台应用程序创建的请求:
// webRequestUrl has been modified
const string webRequestUrl = "http://0.0.0.0/communication/?id={0}&status=70"
var webRequest = WebRequest.Create(string.Format(webRequestUrl, invalidSseLead.LeadId));
try
{
using (var webResponse = (HttpWebResponse)webRequest.GetResponse())
{
if (webResponse != null && webResponse.StatusCode == HttpStatusCode.OK)
{
using (var textStream = new StreamWriter("updateQuery.sql", true))
{
// Write some text
}
}
}
}
catch (Exception exception)
{
// Report exception
}
已检查正在生成的请求 URL,它很好,很困惑为什么它可以在浏览器中工作,但不能在控制台应用程序中工作?
谢谢 :)
Trying to reach a web service URL, works (returns status code 200 as expected) without issue with simple GET from a browser but when executing through console application it is returns status code of 500? I suspect it's proxy or DNS issue but unsure...
Here's request creation from console app:
// webRequestUrl has been modified
const string webRequestUrl = "http://0.0.0.0/communication/?id={0}&status=70"
var webRequest = WebRequest.Create(string.Format(webRequestUrl, invalidSseLead.LeadId));
try
{
using (var webResponse = (HttpWebResponse)webRequest.GetResponse())
{
if (webResponse != null && webResponse.StatusCode == HttpStatusCode.OK)
{
using (var textStream = new StreamWriter("updateQuery.sql", true))
{
// Write some text
}
}
}
}
catch (Exception exception)
{
// Report exception
}
Have checked request URL being generated and it's fine, stumped why it works from browser but not console app?
Thanks :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
该网站是否拒绝编程访问,因此您可能必须使用以下内容来伪造您的用户代理?
Is the site rejecting programmatic access such that you maybe have to fake your user agent using the following?
感谢您的帮助。事实证明,问题实际上出在 URL 上,其中一个可以工作,但生成的另一个则抛出异常。
+1 给 MSMS - 我真的需要复制并粘贴正在生成的确切 URL,而不是使用带有测试数据的 URL
谢谢
Thanks for the assistance. Turned out the problem was in fact with the URL, one worked however a different one being generated was throwing the exception.
+1 to MSMS - I really needed to copy and paste out the exact URL being generated rather than using one with test data
Thanks