1
我的代碼在這裏。如何在發佈數據後讀取WebClient響應? WebClient.UploadData方法(字符串,字符串,字節[])
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 {byte [0]}。
現在,我該如何讀取HTTP輸出?