The file is uploaded via visual studio, but not via .exe

I get the error below when I try to download a .pdf file from a URL through my .exe .

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

but the same thing loads when I try to debug code from visual studio. I am completely lost, I do not know what is happening. Can someone tell me what could be the problem

My App.config file

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

useUnsafeHeaderParsing="true" is the obvious solution that everyone claims on the Internet, unfortunately it does not work.

Here is my web client 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; } } 

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

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

Update 2: I tried to track URL D using a script. When I ran the URL D from the browser to download the file, I got the header below and the file was downloaded . Also note that the D url is redirected to a different URL before loading

 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 downlaod the file with D url using .exe , I got the header

 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 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 
+5
source share

Source: https://habr.com/ru/post/1272192/


All Articles