Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: cURL and HTTP::Request

by Discipulus (Abbot)
on Aug 09, 2022 at 06:48 UTC ( #11146055=note: print w/replies, xml ) Need Help??


in reply to cURL and HTTP::Request

Hello jeanbaptiste93 and welcome to the monastery and to the wonderful world of Perl!

I dont know CURL but our fellow monk Corion (well really a Pope ..mhh Patriarch) wrote a fantastic web service based on his HTTP::Request::FromCurl

So, removing the unkonwn option --url I get, using LWP::UserAgent from the dropdown menu, the following code which might be a nice starting point.

Note that I also removed your PUT

#!perl use strict; use warnings; use LWP::UserAgent; my $ua = LWP::UserAgent->new( 'send_te' => '0' ); my $r = HTTP::Request->new( 'POST' => 'https://[URL]/[ENDPOINT]/item?key=%5BKEY%5D&token=%5BTO +KEN%5D', [ 'Accept' => '*/*', 'User-Agent' => 'curl/7.55.1', 'Content-Length' => '25', 'Content-Type' => 'application/json' ], "{\x22value\x22: {\x22text\x22: \x2238\x22}}" ); my $res = $ua->request( $r, ); __END__ Created from curl command line --request 'https://[URL]/[ENDPOINT]/item?key=[KEY]&token=[TOKEN]' --h +eader 'Content-Type: application/json' --data '{"value": {"text": "38 +"}}'

L*

There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

Replies are listed 'Best First'.
Re^2: cURL and HTTP::Request
by Corion (Patriarch) on Aug 09, 2022 at 07:32 UTC

    Whoops - these two things are bugs/missing implementations. --url should work (but is easily fixed), and --request PUT should properly set the method on the HTTP request (which it currently doesn't). I'll add tests for that and likely release a new version soonish :)

    Update: V 0.41 has just been released and fixes the two issues

Re^2: cURL and HTTP::Request
by jeanbaptiste93 (Novice) on Aug 09, 2022 at 14:24 UTC
    Oh, yes. I also tried that module and had the same --url issue. I tried it with your solution, and it is working for me. You are gold! I have been stuck for this for 2 days, and now I'm getting it to work. Appreciate it a lot!!

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (2)
As of 2022-12-03 01:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?