BookmarkSubscribeRSS Feed
lillejordh
Calcite | Level 5

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>

2 REPLIES 2
AhmedAl_Attar
Ammonite | Level 13

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

lillejordh
Calcite | Level 5

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;

 

 

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1606 views
  • 0 likes
  • 2 in conversation