-
Notifications
You must be signed in to change notification settings - Fork 26
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
Content-Length header is not being set on POST requests. #73
Comments
Can you please post at least a piece of your code that does the request? Of course, with creds and stuff changed. |
Sure. method refreshToken($tokenCode) {
# POST CALL USES THIS FORM DATA
my $form_data = {
grant_type => 'authorization_code',
code => $tokenCode
}
my $response = self.getBearerToken($form_data);
die "Token not refreshed due to unexpected error."
unless self.is-success($response);
# cw: Maybe add code to output response if a flag is set?
die "Invalid response content-type."
unless $response.field('Content-Type') ~~ /^ 'application/json' /;
#my $jsonObj = from-json(await $response.body);
my $jsonObj = await $response.body;
self.setTokenData($jsonObj);
}
# Protected
method getBearerToken($form_data) {
# POST REQUEST MADE HERE.
await $!client.post(
"{ EVE_SSO_PREFIX }/oauth/token",
content-type => 'application/x-www-form-urlencoded',
body => $form_data,
auth => {
username => %!privateData{$!section}<client_id>,
password => %!privateData{$!section}<secret_id>
}
);
} |
Confirmed... Fixing. |
@Xliff It is true that at |
Output with full CRO_TRACE enabled.
|
Why do you have |
Doesn't matter. |
Ok, I'll try it again later. Thanks. |
I still cannot reproduce it with golfing. I've clonned Webservice-EveOnline, but not sure how to run it and what can be needed. |
Unfortunately, you'd have to clone more than that to reproduce the bug, and the isolated version of the code no longer works without WebKitGTK and GTKPlus. All I can tell you is that the content length isn't getting set for specific requests. Here is how I managed a work-around, if that helps: my $body = to-json($form_data, :!pretty);
await $!client.post(
"{ EVE_SSO_PREFIX }/oauth/token",
headers => [
Content-Type => 'application/json',
Content-Length => $body.chars
],
body => $body,
auth => {
username => %!privateData{$!section}<client_id>,
password => %!privateData{$!section}<secret_id>
}
); Without specifying the Content-Length in the above call, it will NOT work, and will throw a 411. Sorry I can't do anything further to illustrate the issue. |
I can reproduce with that code : use Cro::HTTP::Client;
my $user='xxxxxx';
my $password='yyyyyyy';
my $client = Cro::HTTP::Client.new(
base-uri => "https://my-service",
ca => {ca-file => '/etc/ssl/certs/ca-certificates.crt'});
my $body = { grant_type => 'client_credentials' };
my $resp = await $client.post: '/v2/token',
content-type => 'application/x-www-form-urlencoded',
auth => {
username => $user,
password => $password
},
body => $body,
headers => [
Accept => 'application/json;charset=utf-8'
]; Without setting Content-length, i get a HTTP 400 : Parameter grant_type is mandatory. |
I have the following post request captured from using CRO_TRACE=1
This reqeust has the following payload:
The requet fails because the Content-Length header is not present. Is there something special I need to do to get CRO::HTTP::Client to send it?
Thanks
The text was updated successfully, but these errors were encountered: