我想对我的API进行性能测试,用于使用HttpWebRequest上传XML文件。
MVC控制器
[HttpPost]
public bool UploadFile(HttpPostedFileBase file) {
if(file!=null){
///do something
}
}
网络请求代码
string XMLstring = <Details><Name>ABC</Name><City>Mumbai</City></Details>;
string URL = "localhost:1010/ControllerName/UploadFile"
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL);
request.ContentType = "application/x-www-form-urlencoded";
request.Method = "POST";
StringBuilder stringBuilder = new StringBuilder();
try
{
byte[] postData = Encoding.UTF8.GetBytes(XMLstring);
request.ContentLength = postData.Length;
using (Stream requestStream = request.GetRequestStream())
{
requestStream.Write(postData, 0, postData.Length);
}
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
}
}
catch (Exception ex)
{
}
因此调用了Above API,但它在参数中显示为null值。