I am using SAS EG ( SAS 9.4.5.0 ) to connect to an REST API using PROC HTTP:
It is token based.
I get an "< HTTP/1.1 411 Length Required" error.
Question: Is there something else I have to specify to avoid this error?
First step: to get a token works fine.
Step two is a POST where I send a JSON GRAPGQL request together with the token and some extra parameters
( I do the same query in POSTMAN and it works fine)
I feed the Token from a file due to the size(>1000 char)
I feed the GraphQL from a file as well
SAS CODE :
PROC HTTP
url="https://apis.collabor8.no/stable/graph"
method="POST"
ct="application/json"
OAUTH_BEARER=token
out=proddata
in=query;
headers
"Ocp-Apim-Subscription-Key" = "&opcSubscriptionKey"
;
DEBUG LEVEL=3 ;
run;The HTTP input looks like this:
> POST /stable/graph HTTP/1.1
> User-Agent: SAS/9
> Host: apis.collabor8.no
> Accept: */*
> Authorization: Bearer
eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6IlNzWnNCTmhaY0YzUTlTNHRycFFCVEJ5TlJSSSIsImtpZCI6IlNzWnNCTmhaY0YzUT... removed the rest of the token... due to the size
>
> Connection: Keep-Alive
> Content-Length: 618
> Cookie:
ReportingHubAPI=CfDJ8AAt85rvf4dOl01UicW-Bp7Td9gZ9f6LhwHnGt73vIcSJwv3JmNugnkR41JMV313Sz-M4nCB5ctuz2d4bq6p_C_E6ZvCx8BZYeMv4zJ0wnmSBjwB
q3HFe6UjM.... removed the rest due to the size...
2 The SAS System 14:33 Tuesday, June 23, 2020
> Ocp-Apim-Subscription-Key: 322286a3a2f74c15ac3ec6a3c38cac3f
> Content-Type: application/json
>
query { production { data( start: "2020-06-13" end: "2020-06-19" report_data_subtypes: ["Production"]
entity_names_rx: ["/VISUND/i"] limit: 1000 ) { sourceStartTime sourceEndTime dataStartTime
dataEndTime sourceEntity { name type } owningEntity { name type
} dataEntity { name type } dataPeriod name type product
productName qualifier volume { uom value } } }}
The HTTP respons is:
< HTTP/1.1 411 Length Required
< Content-Type: text/html; charset=us-ascii
< Date: Wed, 24 Jun 2020 15:19:51 GMT
< Connection: close
< Content-Length: 344
<
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd"><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>
I Googled "HTTP Error 411. The request must be chunked or have a content length", and the results suggests
adding "Content-Length" = "0" to your headers statement
Hope this helps,
Ahmed
Thanks for your repsonse.
I updated my code to include "Content-Length=0" in the headers - but still I get the same error.
Error:
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>
When I do not include the : "Content-Length=0" SAS sends the length ( e,g. Content-Length: 618 )
SAS code with added Conent-Length
PROC HTTP
url="https://apis.collabor8.no/stable/graph"
method="POST"
ct="application/json"
OAUTH_BEARER=token
out=proddata
in=query;
*VERBOSE ;
headers
"Content-Length" = "0"
"Ocp-Apim-Subscription-Key" = "&opcSubscriptionKey"
;
DEBUG LEVEL=3 ;
run;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.