Question
· Apr 24, 2018

REST- Cache as the server and the client, problem with PUT method , Length required error

Hi,
Trying to work with REST protocol, using IIS 8, both client and server are Cache servers,
I have the following problem- 
When I send a PUT command, I get the following error:
<HTML><HEAD><TITLE>Length Required</TITLE>
<META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii"></HEAD>
<BODY><h2>Length Required</h2>
<hr><p>HTTP Error 411. The request must be chunked or have a content length.</p>
</BODY></HTML>

Get , Post , Delete - work OK.
This problem does not happen if I use Apache, so it's a IIS problem , not a Cache problem.
Searching for solutions on google, this solution is popular-
To fix this error, add an explicit content length to your request before making the API call.
request.ContentLength = 0;

So - using %Net.HttpRequest , how do I accomplish this? ContentLength is a calculated property .
also, did you guys ran into a similar problem using REST ?

Regards,
Nael Nasereldeen
 

Discussion (2)0
Log in or sign up to continue

I have not run into this problem. Also, it appears that Caché already adds the Content-Length header:

  Set req = ##class(%Net.HttpRequest).%New()
  Set req.Server = "www.google.com"
  Do req.EntityBody.Write("test")
  Do req.Put("/", 1)

Yields:

PUT / HTTP/1.1
User-Agent: Mozilla/4.0 (compatible; Cache;)
Host: www.google.com
Accept-Encoding: gzip
Content-Length: 4
Content-Type: text/html; charset=UTF-8
test
 

I suspect Content-Length isn't the actual issue. I don't have any ideas about what is, though. (Perhaps you should at least check if your Caché sends it.)