I created a service that takes 2 things:
1) The body parameter, called "type".
2) Downloadable csv file.
I read these two things on the server side as follows:
string type = HttpContext.Current.Request.Form["type"];
Stream csvStream = HttpContext.Current.Request.Files[0].InputStream;
How can I check this, I use Fiddler to check this, but I can only send one thing at a time (type or file), because both things have different types of content, how can I use the content type multipart / form-data Strong> and application / x-www-form-urlencoded at the same time.
Even i use this code
public static void PostDataCSV()
{
byte[] fileToSend = File.ReadAllBytes(@"C:\SampleData.csv");
string url = "http://localhost/upload.xml";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "POST";
request.ContentType = "multipart/form-data";
request.ContentLength = fileToSend.Length;
using (Stream requestStream = request.GetRequestStream())
{
requestStream.Write(fileToSend, 0, fileToSend.Length);
requestStream.Close();
}
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
string result;
using (StreamReader reader = new StreamReader(response.GetResponseStream()))
{
result = reader.ReadToEnd();
}
Console.WriteLine(result);
}
It is also not sending any files to the server.
source
share