我正在尝试完全像浏览器(chrome)一样模拟HTTP发布文件:
HTML:
<form name="fnup" method="post" action="action.shtml" enctype="multipart/form-data">
<input name="firmfile" id="firmfile" type="file">
<input type="submit" id="firmbutton" value="Upgrade" class="othsave">
</form>
C#:
public async Task<string> UploadFile(string actionUrl, string filePath)
{
var httpClient = new HttpClient();
//Should I need to add all those headers??? it will help me? what is necessary?
httpClient.DefaultRequestHeaders.Add("Upgrade-Insecure-Requests", "1");
httpClient.DefaultRequestHeaders.Add("Origin", "http://" + ip);
httpClient.DefaultRequestHeaders.Add("Upgrade-Insecure-Requests", "1");
httpClient.DefaultRequestHeaders.Add("Pragma", "no-cache");
C#示例在我的服务器上不起作用,我不明白为什么...
在查看Wireshark之后,我看到了一些不同之处:
铬:
C#
问题:
1)我如何删除"filename*=utf-8''VP445_all_V116.bin"
从Content-Disposition
2)为什么我不能看到第二行Content-Type: application/octet-stream
像在Chrome?
3)内容长度也不相同(甚至是相同的文件)
4)底线是C#无法正常工作,chrome正在正常工作,并且服务器端对我来说是黑匣子,所以我需要猜这里我在C#发布请求中做错了什么。
相关分类