【发布时间】:2014-07-02 20:50:12
【问题描述】:
尝试上传 xml 文件时,此特定服务器返回错误(上述异常)。 我在另一台服务器 (https://posttestserver.com/post.php) 上尝试了另一个 url,并且代码有效。 我的同事能够通过 Perl 脚本上传相同的 xml 文件。
我的问题是:还有其他方法可以上传文件的内容吗?试过UploadData,UploadString,还是一样的错误。
// Create the xml document file
Byte[] buffer = new Byte[ms.Length];
buffer = ms.ToArray();
xmlOutput = System.Text.Encoding.UTF8.GetString(buffer);
string filePath = @"c:\my.xml");
File.WriteAllText(filePath, xmlOutput);
try
{
ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;
using (WebClient client = new WebClient())
{
byte[] rawResponse = client.UploadFile(url, filePath);
string response = System.Text.Encoding.ASCII.GetString(rawResponse);
}
}
catch (WebException ex)
{
}
catch (Exception ex)
{
}
【问题讨论】:
-
您是否安装了fiddler 并检查了您发送的请求?
标签: c# system.net