10
如何在WebApi中添加和获取Header值
我需要在WebApi中创建POST方法,以便可以将数据从应用程序发送到WebApi方法。我无法获取标头值。 在这里,我在应用程序中添加了标头值: using (var client = new WebClient()) { // Set the header so it knows we are sending JSON. client.Headers[HttpRequestHeader.ContentType] = "application/json"; client.Headers.Add("Custom", "sample"); // Make the request var response = client.UploadString(url, jsonObj); } 遵循WebApi post方法: public string Postsam([FromBody]object jsonData) { HttpRequestMessage re = new HttpRequestMessage(); var headers = …