文件通过visual studio下载,但不是通过.exe下载

当我尝试通过我的.exe文件从URL下载.pdf文件时,我得到以下错误。

服务器提交了协议违规。 Section = ResponseHeader Detail = CR必须后跟LF

但是当我尝试从visual studio调试代码时,同样会下载。 我完全迷失了,不知道最近发生了什么。 有人可以告诉我可能是什么问题

我的App.config文件

         

useUnsafeHeaderParsing="true"是一个明显的解决方案,每个人都在互联网上说不幸它不工作

这是我的webclient代码

 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; } } 

更新:我的.exe能够下载大部分url,除了少数。 考虑我有4个url: A,B,C and D 我的视觉工作室能够从所有4个url下载文件,但我的.exe下载文件来自前3个url。 对于url, D它会抛出

服务器提交了协议违规。 Section = ResponseHeader Detail = CR必须后跟LF

更新2:我试图使用fiddler跟踪D url。 当我从浏览器运行D url下载文件时,我得到了以下标题并下载了文件。 另请注意,在下载之前, D url会重定向到另一个URL

 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 

当我尝试使用.exeD url下载文件时,我得到了以下标题

 CONNECT www.loim.com:443 HTTP/1.1 Host: www.loim.com Connection: Keep-Alive 

出于某种原因, User-Agent就是问题所在?

Update3: bin \ debug的dir /s /b

 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 

应用程序配置文件需要与.exe位于同一文件夹中。 部署CLImport.exe ,还应将CLImport.exe.config部署到该文件夹​​。