Published on :
Data Integration GENERATION_INTERNE_ET_EXTERNE

HTTP POST Request and JSON Processing

This code is also available in: Deutsch Español Français
Awaiting validation
The script uses `PROC HTTP` to send encoded data (custname, size, topping) via a POST request to the `/post` endpoint of `httpbin.org`. The JSON response from the web service is stored in a temporary file. A `DATA _NULL_` step then uses the `jsonpp` function to parse and format the JSON content of this response, displaying it legibly in the SAS© log.
Data Analysis

Type : GENERATION_INTERNE_ET_EXTERNE


The body of the POST request is defined internally within the script. The response (JSON data) is received from an external web service (`httpbin.org`).

1 Code Block
PROC HTTP Data
Explanation :
This block establishes an HTTP connection and sends a POST request with specific parameters to the target URL. The server's response is captured and written to a temporary file named 'resp'.
Copied!
1filename resp temp;
2PROC HTTP
3 url="http://httpbin.org/post"
4 method="POST"
5 in="custname=Joe%str(&)size=large%str(&)topping=cheese"
6 out=resp;
7RUN;
2 Code Block
DATA STEP
Explanation :
This `DATA _NULL_` block uses the `jsonpp` function to read the JSON content from the temporary file 'resp' and format it neatly in the SAS log, making it easier to read and examine.
Copied!
1DATA _null_;
2 rc = jsonpp('resp','log');
3RUN;
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.