【发布时间】:2018-02-07 20:19:25
【问题描述】:
我的代码在这里。
string uriString = "http://www.Testcom";
WebClient myWebClient = new WebClient();
string postData = "data";
myWebClient.Headers.Add("Content-Type","application/x-www-form-urlencoded");
Console.WriteLine(myWebClient.Headers.ToString());
byte[] byteArray = Encoding.ASCII.GetBytes(postData);
byte[] responseArray = myWebClient.UploadData(new
Uri(uriString),"POST",byteArray);
现在我调用 UploadData 并获取在我的 API 项目中创建的方法,如下所示。
[HttpPost]
[Route("doc2pdf")]
public HttpResponseMessage doc2pdf(byte[] fileContent)
{
string pdfContent = string.Empty;
//if(string.IsNullOrEmpty(docContent))
//{
// var resp = Request.CreateResponse(HttpStatusCode.BadRequest,"Document content is empty.");
// return resp;
//}
if(fileContent != null || fileContent.Length > 0)
{
..logic here
}
}
问题始终是 fileContent 获取 {byte[0]}。
现在,我如何读取 HTTP 输出?
【问题讨论】:
标签: c# asp.net api c#-4.0 asp.net-web-api