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

时间:2022-09-12 08:19:17

Am getting the below error when I try to download the a .pdf file from a url through my .exe file.

当我试图通过我的.exe文件从url下载.pdf文件时,我得到了下面的错误。

The server committed a protocol violation. Section=ResponseHeader Detail=CR must be followed by LF

服务器违反了协议。必须在后面加上LF。

but the same is getting downloaded when I try to debug the code from visual studio. I am totally lost, no clue of whats going on. Can somebody tell me what could be the problem

但是当我试图调试visual studio中的代码时,同样的情况也会被下载。我完全迷路了,一点线索也没有。谁能告诉我是什么问题吗

My App.config file

我的App.config文件

<?xml version="1.0"?>
<configuration>
  <system.net>
    <settings>
      <httpWebRequest useUnsafeHeaderParsing="true" />
    </settings>
  </system.net>
</configuration>

useUnsafeHeaderParsing="true" is the obvious fix that everyone is stating on internet unfortunately it is not working

useunsafeheaderparser ="true"是显而易见的修正,每个人都在网上声明它不工作

Here is my webclient code

这是我的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;
    }
}

Update : My .exe was able to download most of the url's except few. Consider I have 4 url's :A,B,C and D. My visual studio was able to download files from all 4 urls' but my .exe download's file from first 3 url's. For url, D it throws

更新:我的。exe能够下载url的大部分,除了少数。假设我有4个url:A、B、C和d。对于url,它会抛出。

The server committed a protocol violation. Section=ResponseHeader Detail=CR must be followed by LF

服务器违反了协议。必须在后面加上LF。

Update 2 : I was trying to trace D url using fiddler. When I ran the D url from browser to download the file, I got the below header and file was downloaded. Also note that D url is redirected to another url before downloading

更新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

When I tried to downlaod the file from D url using .exe I got the below header

当我试图用。exe从D url下拉文件时,我得到了下面的头文件

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

For some reason the User-Agent is that the problem ?

由于某种原因,用户代理是问题所在吗?

Update3: dir /s /b of the bin\debug

更新3: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

1 个解决方案

#1


3  

The application configuration file needs to be in the same folder as the .exe. When you deploy CLImport.exe you should also deploy CLImport.exe.config to that folder.

应用程序配置文件需要与.exe位于同一个文件夹中。当你部署CLImport。你还应该部署CLImport.exe。配置文件夹。

#1


3  

The application configuration file needs to be in the same folder as the .exe. When you deploy CLImport.exe you should also deploy CLImport.exe.config to that folder.

应用程序配置文件需要与.exe位于同一个文件夹中。当你部署CLImport。你还应该部署CLImport.exe。配置文件夹。