Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: REST::Client + Request Body

by hippo (Bishop)
on Jul 07, 2020 at 11:39 UTC ( [id://11118999]=note: print w/replies, xml ) Need Help??


in reply to REST::Client + Request Body

This is not working

Your code starts with Use REST::Client; when it should be use REST::Client; because Perl is case-sensitive and use needs to be all lowercase. It's no surprise it isn't working.

You may also need to set some headers depending on what the server expects. Here is a fully working SSCCE to get you started.

#!/usr/bin/env perl use strict; use warnings; use REST::Client; my $rest = REST::Client->new ({ host => 'http://httpbin.org' }); my $data = '{"key":"value"}'; my $headers = { Accept => 'application/json', 'Content-type' => 'application/json', }; $rest->POST ('/anything', $data, $headers); print $rest->responseContent;

Replies are listed 'Best First'.
Re^2: REST::Client + Request Body
by ravigupta1 (Novice) on Jul 07, 2020 at 11:50 UTC

    Hi, Thanks for your prompt response.

    it was a typo as i cannot copy/paste my code here, so i wrote it manually here.

    Headers i know how to set but as I am new to PERL i don't know how to pass authToken as Request Body. Appreciate if you could help me .... how to pass this value as Request Body or may be share some URL from where i could learn this.

    regards, Ravi

      In my SSCCE the request body is held in $data. It is in a format called JSON. If the server expects a JSON payload then you just need to construct one along the same lines and send it.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11118999]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (1)
As of 2024-04-19 18:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found