我的密码在这里。
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 get {字节}。

现在,如何读取HTTP输出?
发布于 2017-08-30 17:37:11
在WebApi中发送数据的更好方法是使用JSON。但是,如果要使用表单编码的数据,则应:
public HttpResponseMessage doc2pdf([FromBody]string fileContent)所以,客户端代码
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);服务器端代码
public HttpResponseMessage doc2pdf([FromBody]string fileContent)
{
//..logic here
}https://stackoverflow.com/questions/45954972
复制相似问题