Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot POST with proper json headers with libcurl 7.82.0 #33

Open
bduggan opened this issue May 4, 2022 · 1 comment
Open

Cannot POST with proper json headers with libcurl 7.82.0 #33

bduggan opened this issue May 4, 2022 · 1 comment

Comments

@bduggan
Copy link
Contributor

bduggan commented May 4, 2022

Hi Curt,

It doesn't seem possible to send both Accept: application/json and Content-Type: application/json using LibCurl with version 7.82.0 of the library. This may be an issue with libcurl, not sure. Here are a couple of the things I've tried:

use LibCurl::HTTP :subs;
say jpost('https://httpbin.org/post', %(Content-Type => 'application/json', Accept => 'application/json'));
# sends "Accept => */*"
say jpost('https://httpbin.org/post', %(Content-Type => 'application/json', Accept => 'application/json'), :x<z>);
# sends "Content-Type => application/x-www-form-urlencoded"
my $curl = LibCurl::Easy.new(URL => 'http://httpbin.org/post');
$curl.setopt(post => 1);
$curl.set-header(Accept => 'application/json');
$curl.set-header(Content-Type => 'application/json');
say $curl.perform.content;
# sends "Accept": "*/*",

For the last one -- changing the order of calling set-header seems to make a difference:

my $curl = LibCurl::Easy.new(URL => 'http://httpbin.org/post');
$curl.setopt(post => 1);
$curl.set-header(Content-Type => 'application/json');
$curl.set-header(Accept => 'application/json');
say $curl.perform.content;
# Sends "Content-Type": "application/x-www-form-urlencoded"

Not sure if there is some other order of calling these methods that will work -- as far as I can tell, it's impossible to set both the Accept and the Content-Type header to application/json for a POST request.

Brian

@meowmeowarmy
Copy link

meowmeowarmy commented Aug 3, 2022

I'm having the same issue. It only seems to send 1 of the headers when you have more than 1.

libcurl4 - 7.81.0
Ubuntu 22.04 LTS
Rakudo Star - v2022.07

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants