Webclient上传文件 - 内部服务器错误500

时间:2012-07-15 17:14:44

标签: c# curl

我一直试图通过以下C#代码模拟以下cURL命令:

curl.exe –v –u user:pwd –XPOST –T "file1.txt" –H "Content-Type:text/plain" "http://example.com/xx/xx/xx/insert"
string url = "http://example.com/xx/xx/xx/insert";
string fileName = @"file1.txt";

var client = new WebClient();
client.Credentials = new NetworkCredential("user", "pwd");
client.Headers.Add("Content-Type", "text/plain");         
byte[] responseBinary = client.UploadFile(url, "POST", fileName);
string response = Encoding.UTF8.GetString(responseBinary);

它给我一个“内部服务器错误500”。我认为我要上传的服务器是PHP服务器。我该如何进行调试?

1 个答案:

答案 0 :(得分:0)

更新:

我正在通过fiddler调试cURL和webclient(控制台应用程序)的流量。看起来cURL只发送file1.txt的内容并将标题保持为“text / plain”。 webclient将Content-Disposition,filename,content-type添加到file1.txt的内容中,并将标题设置为“multipart / form-data”。

无论如何我可以阻止webclient这种行为吗?

谢谢, 卡努