[英]two “Content-Type” in webclient header
var uri = URL_BASE + myuri
string.Format("providers/{0}/items?feed={1}&id={2}&type=cf", provider, feed, zipFileNoPath);
var webClient = new WebClient();
webClient.Credentials = new NetworkCredential(email, password);
webClient.Headers.Add("Accept", "*/*");
webClient.Headers.Add("Content-Type", "application/octet-stream");
webClient.UploadFileAsync(new Uri(uri), "POST", zipFile);
对于上面的代码,当我从提琴手观看时,我在标题中看到了两个“ Content-Type”,一个是Content-Type:multipart / form-data; boundary = --------------------- 8cf27396e080e0a,另一个是Content-Type:application / octet-stream为什么会是谁? 然后哪个人生效,谢谢
在其他值中将二进制数据发布到服务器时,将添加“ boundary”参数。 这是为了使服务器能够识别数据的边界-边界参数的值是随机的并且是经过挑选的,因此字符串永远不会出现在发布的数据中(因此可以作为边界服务器)。
我猜想webclient
会自动添加它,如果是这样,您可以在我们自己的添加该标头的行中添加注释。 不幸的是,我不知道HTTP规范可以告诉您重复的标头是否有效。
使用UploadData代替UploadFile
var webClient = new WebClient();
webClient.Credentials = new NetworkCredential(email, password);
webClient.UploadDataCompleted += webClient_UploadDataCompleted;
byte[] fileBytes = File.ReadAllBytes(zipFile);
webClient.UploadDataAsync(new Uri(uri), "POST", fileBytes);
那我只会看到一个Content-Type
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.