通过POST请求提交CSV - 发布空转(c#)

时间:2012-12-29 07:11:05

标签: c# .net post

我正在尝试从文件中读取CSV并通过POST请求提交。由于某种原因,请求中没有发送任何数据。谁能看到我的代码出了什么问题?

    FileStream rdr = new FileStream(path, FileMode.Open, FileAccess.Read);
    byte[] inData = new byte[rdr.Length];
    rdr.Read(inData, 0, Convert.ToInt32(rdr.Length));

    HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
    req.KeepAlive = false;
    req.ContentType = GetContentType(path);
    req.Method = "POST"; 
    req.ContentLength = rdr.Length;
    req.AllowWriteStreamBuffering = true;

    Stream reqStream = req.GetRequestStream();

    reqStream.Write(inData, 0, Convert.ToInt32(rdr.Length));

    Stream dataStream = req.GetResponse().GetResponseStream();
    StreamReader reader = new StreamReader(dataStream);
    responseFromServer = responseFromServer + reader.ReadToEnd();

    rdr.Close();
    reqStream.Close();

1 个答案:

答案 0 :(得分:0)

我确定需要将CSV数据作为变量的值提交。我正在发布的第三方可以提前提到。谢谢你的帮助。