当我尝试下载 a 时出现以下错误.pdf
通过我的网址从文件.exe
file.
服务器违反了协议。部分=响应头
详细信息=CR 后必须跟 LF
但当我尝试从 Visual Studio 调试代码时,也会下载同样的内容。我完全迷失了,不知道发生了什么。有人可以告诉我可能是什么问题吗
My App.config
file
<?xml version="1.0"?>
<configuration>
<system.net>
<settings>
<httpWebRequest useUnsafeHeaderParsing="true" />
</settings>
</system.net>
</configuration>
useUnsafeHeaderParsing="true"
是每个人都在互联网上声明的明显修复,不幸的是它不起作用
这是我的网络客户端代码
public class CookieAwareWebClient : WebClient {
private CookieContainer cc = new CookieContainer();
private string lastPage;
protected override WebRequest GetWebRequest(Uri address) {
if (address.Scheme == Uri.UriSchemeHttps) {
ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072 | SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls;
// allows for validation of SSL conversations
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
}
WebRequest R = base.GetWebRequest(address);
if (R is HttpWebRequest) {
HttpWebRequest wr = (HttpWebRequest)R;
wr.CookieContainer = cc;
if (lastPage != null) {
wr.Referer = lastPage;
}
}
lastPage = address.ToString();
return R;
}
}
Update : My .exe
能够下载大多数网址,除了少数。考虑我有 4 个网址:A,B,C and D
。我的视觉工作室能够从所有 4 个网址下载文件,但我的.exe
从前 3 个网址下载文件。对于网址,D
它抛出
服务器违反了协议。部分=响应头
详细信息=CR 后必须跟 LF
更新2:我试图追踪D
使用提琴手的网址。当我运行D
从浏览器下载文件的 url,我得到以下标头和文件下载的。另请注意D
url is 重定向下载前转到另一个网址
CONNECT www.loim.com:443 HTTP/1.1
Host: www.loim.com:443
Connection: keep-alive
User-Agent: Mozilla/5.0 (Windows NT 6.2; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36
当我尝试从以下位置下载文件时D
网址使用.exe
我得到了下面的标题
CONNECT www.loim.com:443 HTTP/1.1
Host: www.loim.com
Connection: Keep-Alive
由于某种原因User-Agent
这就是问题所在吗?
Update3: dir /s /b
bin\debug 的
C:\Pradeep\TFS\proj\bin\Debug\app.publish
C:\Pradeep\TFS\proj\bin\Debug\CLImport.application
C:\Pradeep\TFS\proj\bin\Debug\CLImport.exe
C:\Pradeep\TFS\proj\bin\Debug\CLImport.exe.config
C:\Pradeep\TFS\proj\bin\Debug\CLImport.exe.manifest
C:\Pradeep\TFS\proj\bin\Debug\CLImport.pdb
C:\Pradeep\TFS\proj\bin\Debug\CLImport.vshost.application
C:\Pradeep\TFS\proj\bin\Debug\CLImport.vshost.exe
C:\Pradeep\TFS\proj\bin\Debug\CLImport.vshost.exe.config
C:\Pradeep\TFS\proj\bin\Debug\CLImport.vshost.exe.manifest
C:\Pradeep\TFS\proj\bin\Debug\FED.Business.Collection.dll
C:\Pradeep\TFS\proj\bin\Debug\FED.Business.Collection.pdb
C:\Pradeep\TFS\proj\bin\Debug\FED.Data.Collection.dll
C:\Pradeep\TFS\proj\bin\Debug\FED.Data.Collection.pdb
C:\Pradeep\TFS\proj\bin\Debug\FED.DataSource.Utilities.dll
C:\Pradeep\TFS\proj\bin\Debug\FED.DataSource.Utilities.pdb
C:\Pradeep\TFS\proj\bin\Debug\GemBox.Spreadsheet.dll
C:\Pradeep\TFS\proj\bin\Debug\ICSharpCode.SharpZipLib.dll
C:\Pradeep\TFS\proj\bin\Debug\Ignored
C:\Pradeep\TFS\proj\bin\Debug\itextsharp.dll
C:\Pradeep\TFS\proj\bin\Debug\Microsoft.Exchange.WebServices.dll
C:\Pradeep\TFS\proj\bin\Debug\Processed
C:\Pradeep\TFS\proj\bin\Debug\tt.text
C:\Pradeep\TFS\proj\bin\Debug\app.publish\CLImport.exe