Hello I Have a request in web form code behind and i like call web api send Object with a property of type IFormCollection, the object properties sending but file not
WebRequest wrqst = WebRequest.Create(URLService + method);
var postData = new StringBuilder();
foreach (string key in form.Keys)
{
postData.AppendFormat("{0}={1}&",
HttpUtility.UrlEncode(key),
HttpUtility.UrlEncode(form[key]));
}
var data = Encoding.ASCII.GetBytes(postData.ToString());
wrqst.Method = "POST";
wrqst.ContentType = "application/x-www-form-urlencoded";
wrqst.ContentLength = data.Length;
using (var stream = wrqst.GetRequestStream())
{
stream.Write(data, 0, data.Length);
}
WebResponse oResponse = wrqst.GetResponse();
I Receive file in Request.File
How i can send File?
2
Answers
To send a file in your web API request, you need to use the multipart/form-data content type instead of application/x-www-form-urlencoded.