I want to send .csv file in a POST
request where content type is "multipart/form-data" and in the body there is some key and the .csv file
Below is the code I have tried:
string url = "*****URL*****";
string root = AppDomain.CurrentDomain.BaseDirectory;
string file = root + "Folder\\file.csv";
FileInfo fileInfo = new FileInfo(file);
int fileLength = (int)fileInfo.Length;
FileStream rdr = new FileStream(file, FileMode.Open);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "POST";
request.ContentType = "multipart/form-data";
request.Headers["Content-Type"] = "multipart/form-data";
int bytesRead = 0;
byte[] requestByte = new byte[fileLength];
request.ContentLength = requestByte.Length;
using (Stream requestStream = request.GetRequestStream())
{
while ((bytesRead = rdr.Read(requestByte, 0, requestByte.Length)) != 0)
{
requestStream.Write(requestByte, 0, bytesRead);
requestStream.Close();
}
}
string responseData;
using (StreamReader responseStream = new StreamReader(request.GetResponse().GetResponseStream()))
{
responseData = responseStream.ReadToEnd();
responseStream.Close();
}
But this is giving error in the content type, may be I am doing it wrong. Please help me out here.