1
WebClient를 사용하여 webapi로 데이터를 보내려고합니다. 코드를 실행하면 제목에 예외가 표시됩니다. 누군가 나를 도울 수 있습니까? 당신은 HttpWebRequest
사용할 수있는 헤더 정의'Content-Length'헤더는 해당 속성이나 메서드를 사용하여 수정해야합니다. 매개 변수 이름 : 이름
using (WebClient wc = new WebClient())
{
wc.Headers[HttpRequestHeader.ContentType] = "application/json";
wc.Headers[HttpRequestHeader.Authorization] = headerString;
data = Encoding.UTF8.GetBytes(jsonData);
string contentLength = data.Length.ToString();
wc.Headers[HttpRequestHeader.ContentLength] = contentLength;
wc.Headers[HttpRequestHeader.Accept] = "application/json";
wrCache = new CredentialCache();
wrCache.Add(new Uri(URI), "Basic", new NetworkCredential("user1", "[email protected]"));
wc.Credentials = wrCache;
byte[] htmlResult = wc.UploadData(URI, "POST", data);