文件是通过Visual Studio下载的,而不是通过.exe下载的 [英] File is downloading through visual studio but not through .exe

查看:74
本文介绍了文件是通过Visual Studio下载的,而不是通过.exe下载的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试通过我的.exe文件从URL下载一个.pdf文件时,出现以下错误.

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

服务器犯了协议冲突. Section = ResponseHeader Detail = CR后面必须加上LF

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

,但是当我尝试从Visual Studio调试代码时,会下载相同的内容.我完全迷路了,不知道发生了什么.有人可以告诉我可能是什么问题

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

我的App.config文件

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

useUnsafeHeaderParsing="true"是每个人都在互联网上指出的不幸问题,很明显它无法正常工作

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

这是我的网络客户端代码

Here is my webclient code

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个网址:A,B,C and D.我的Visual Studio能够从所有4个URL下载文件,但我的.exe下载文件是从前3个URL下载文件.对于网址,D它会引发

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

服务器犯了协议冲突. Section = ResponseHeader Detail = CR后面必须加上LF

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

更新2:我正在尝试使用提琴手来跟踪D网址.当我从浏览器运行D网址以下载文件时,我得到了以下标题,并且文件已下载.另外请注意,在下载

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

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网址下载文件时,出现了以下标题

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

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

由于某些原因,User-Agent是问题所在吗?

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

Update3:的bin \ debug

Update3: dir /s /b of the 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

推荐答案

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

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.

这篇关于文件是通过Visual Studio下载的,而不是通过.exe下载的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆