C#
HTTP 411 오류? The remote server returned an error: (411) Length Required.
saltdoll
2018. 5. 5. 04:29
반응형
보통 HttpWebRequest and POST method를 사용할 때, POST내용의 Size를 빼먹곤 한다.
그럴 경우, 아래와 같이 411 HTTP 통신 Error가 발생된다.
Exception Details: System.Net.WebException: The remote server returned an error: (411) Length Required.
request.Method가 GET의 경우는 문제가 되지 않지만, POST에는 무조건 넘겨줘야 한다.
When you're using HttpWebRequest and POST method, you have to set a content (or a body if you prefer) via the RequestStream. But, according to your code, using authRequest.Method = "GET" should be enough.
In case you're wondering about POST format, here's what you have to do :
ASCIIEncoding encoder = new ASCIIEncoding();
byte[] data = encoder.GetBytes(serializedObject); // a json object, or xml, whatever...
HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
request.Method = "POST";
request.ContentType = "application/json";
request.ContentLength = data.Length;
request.Expect = "application/json";
request.GetRequestStream().Write(data, 0, data.Length);
HttpWebResponse response = request.GetResponse() as HttpWebResponse;
Http 411 에러는 Length 요청 에러~~!!
참고: https://stackoverflow.com/questions/18352190/why-i-get-411-length-required-error
반응형