我现在花了很多时间来配置我的代理。目前,我使用一项名为 proxybonanza 的服务。他们为我提供了一个代理,我用它来获取网页。
我正在使用HTMLAGILITYPACK
现在,如果我在没有代理的情况下运行我的代码,则在本地或上传到虚拟主机服务器时都没有问题。
如果我决定使用代理,它需要更长的时间,但它仍然可以在本地工作。
If I publish my solution to, to my webhost I get a SocketException (0x274c)
"A connection attempt failed because the connected party did not properly respond
after a period of time, or established connection failed because connected host has
failed to respond 38.69.197.71:45623"
我已经调试了很长时间。
我的 app.config 有两个与此相关的条目
httpWebRequest useUnsafeHeaderParsing="true"
httpRuntime executionTimeout="180"
这帮助我解决了几个问题。
现在这是我的 C# 代码。
HtmlWeb htmlweb = new HtmlWeb();
htmlweb.PreRequest = new HtmlAgilityPack.HtmlWeb.PreRequestHandler(OnPreRequest);
HtmlDocument htmldoc = htmlweb.Load(@"http://www.websitetofetch.com,
"IP", port, "username", "password");
//This is the preRequest config
static bool OnPreRequest(HttpWebRequest request)
{
request.KeepAlive = false;
request.Timeout = 100000;
request.ReadWriteTimeout = 1000000;
request.ProtocolVersion = HttpVersion.Version10;
return true; // ok, go on
}
我究竟做错了什么?我在 appconfig 中启用了跟踪器,但我的虚拟主机上没有日志...?
Log stuff from app.config
<system.diagnostics>
<sources>
<source name="System.ServiceModel.MessageLogging" switchValue="Warning, ActivityTracing" >
<listeners>
<add name="ServiceModelTraceListener"/>
</listeners>
</source>
<source name="System.ServiceModel" switchValue="Verbose,ActivityTracing">
<listeners>
<add name="ServiceModelTraceListener"/>
</listeners>
</source>
<source name="System.Runtime.Serialization" switchValue="Verbose,ActivityTracing">
<listeners>
<add name="ServiceModelTraceListener"/>
</listeners>
</source>
</sources>
<sharedListeners>
<add initializeData="App_tracelog.svclog"
type="System.Diagnostics.XmlWriterTraceListener, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
name="ServiceModelTraceListener" traceOutputOptions="Timestamp"/>
</sharedListeners>
</system.diagnostics>
谁能发现我将这些设置打开和关闭一千次的问题..
request.KeepAlive = false;
System.Net.ServicePointManager.Expect100Continue = false;
卡尔