嗨,我有以下代码发送数据,但作为回报,我收到服务器错误,错误代码为500,文件为 没有通过请求发送
谁能告诉我我在做什么错
FileStream rdr = new FileStream("C:/Users/AR485UY/Desktop/Test1.pdf", FileMode.Open)
HttpWebRequest req = (HttpWebRequest)WebRequest.Create("url" );
string boundary = "----------------------------" + DateTime.Now.Ticks.ToString("x");
req.Method = "POST";
req.ContentLength = rdr.Length;
req.ContentType = "multipart/form-data; boundary=" +boundary;
req.AllowWriteStreamBuffering = true;
Stream reqStream = req.GetRequestStream();
byte[] inData = new byte[rdr.Length];
int len = Convert.ToInt32(rdr.Length);
int bytesRead = rdr.Read(inData, 0, len);
reqStream.Write(inData, 0, len);
rdr.Close();
req.GetResponse();
reqStream.Close();
答案 0 :(得分:0)
HTTP 500 Internal Server Error服务器错误响应代码表示服务器遇到意外状况,阻止其满足请求。
如果它永远不起作用: 最有可能必须验证您的服务器端api,脚本,日志,事件,诊断跟踪,文件大小限制。
也可以尝试使用c#的另一种方法:
try
{
using(WebClient client = new WebClient())
{
string myFile = @"C:/Users/AR485UY/Desktop/Test1.pdf";
client.Credentials = CredentialCache.DefaultCredentials;
client.UploadFile(url, "POST", myFile);
}
}
catch (Exception err)
{
MessageBox.Show(err.Message);
}