Pரத*_*ீப் 5 .net c# httpwebrequest
当我尝试.pdf通过我的文件从URL 下载文件时,我得到以下错误.exe.
服务器提交了协议违规.Section = ResponseHeader Detail = CR必须后跟LF
但是当我尝试从visual studio调试代码时,同样会被下载.我完全迷失了,不知道最近发生了什么.有人能告诉我可能是什么问题
我的App.config档案
<?xml version="1.0"?>
<configuration>
<system.net>
<settings>
<httpWebRequest useUnsafeHeaderParsing="true" />
</settings>
</system.net>
</configuration>
Run Code Online (Sandbox Code Playgroud)
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;
}
}
Run Code Online (Sandbox Code Playgroud)
更新:我.exe能够下载大部分网址,除了少数.考虑我有4个网址:A,B,C and D.我的视觉工作室能够从所有4个网址下载文件,但我的.exe下载文件来自前3个网址.对于网址,D它会抛出
服务器提交了协议违规.Section = ResponseHeader Detail = CR必须后跟LF
更新2: 我试图D使用fiddler 跟踪网址.当我跑的DURL从浏览器下载文件时,我得到了下面的标题和文件下载.另请注意,在下载之前,Durl会重定向到另一个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
Run Code Online (Sandbox Code Playgroud)
当我尝试从Durl 下载文件时,.exe我得到了以下标题
CONNECT www.loim.com:443 HTTP/1.1
Host: www.loim.com
Connection: Keep-Alive
Run Code Online (Sandbox Code Playgroud)
出于某种原因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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
347 次 |
| 最近记录: |