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

cpr::Post wrong content length #450

Closed
COM8 opened this issue Sep 23, 2020 · 5 comments
Closed

cpr::Post wrong content length #450

COM8 opened this issue Sep 23, 2020 · 5 comments
Labels

Comments

@COM8
Copy link
Member

COM8 commented Sep 23, 2020

I have a similar question. Here's the code I wrote. Run it, I found some problems by Wireshark. Content-Length is 240518168632, and Expect is 100-continue. Please help me, thanks.

std::string body = "{\"RegisterObject\": {\"DeviceID\": \"65010000005030000001\"}}";
auto response    = cpr::Post(cpr::Url{"http://10.10.10.235:14000/VIID/System/Register"},
                               cpr::Header{{"Content-Type", "application/json"}}, cpr::Body{body},
                               cpr::ConnectTimeout{3000}, cpr::Timeout{3000});

cpr

Originally posted by @bayec in #449 (comment)

@COM8
Copy link
Member Author

COM8 commented Sep 23, 2020

@bayec, which version of cpr are you using?
I remember I have fixed this one early in the development cycle of v1.5.0.
I Also created a quick unit test and to me it looks like its working with the current master build.

TEST(UrlEncodedPostTests, TimeoutPostTest) {
    Url url{server->GetBaseUrl() + "/json_post.html"};
    std::string body{"{\"RegisterObject\": {\"DeviceID\": \"65010000005030000001\"}}"};
    cpr::Response response =
            cpr::Post(url, cpr::Header{{"Content-Type", "application/json"}}, cpr::Body{body},
                      cpr::ConnectTimeout{3000}, cpr::Timeout{3000});
    std::string expected_text{"{\"RegisterObject\": {\"DeviceID\": \"65010000005030000001\"}}"};
    EXPECT_EQ(expected_text, response.text);
    EXPECT_EQ(url, response.url);
    EXPECT_EQ(std::string{"application/json"}, response.header["content-type"]);
    EXPECT_EQ(201, response.status_code);
    EXPECT_EQ(ErrorCode::OK, response.error.code);
}

COM8 added a commit that referenced this issue Sep 23, 2020
@cyanhill
Copy link

@COM8
I also found this problem, it seems to be caused by CURLOPT_POSTFIELDSIZE_LARGE, modify it to CURLOPT_POSTFIELDSIZE to correctly calculate the json length.

@COM8
Copy link
Member Author

COM8 commented Sep 23, 2020

AH!
Thanks @cyanhill.
I might have found it.

Setting CURLOPT_POSTFIELDSIZE_LARGE requires a value of type curl_off_t, which usually is 64 bit. If you pass it a simple size_t like std::string::length() returns it, it might be a mismatch (32 to 64 bit).

curl_easy_setopt(CURL *handle, CURLOPT_POSTFIELDSIZE_LARGE, curl_off_t size);

COM8 added a commit that referenced this issue Sep 23, 2020
@COM8
Copy link
Member Author

COM8 commented Sep 23, 2020

I've pushed a potential fix for this issue.
Please let me know, if this fixes it.

@bayec
Copy link

bayec commented Sep 23, 2020

@COM8 @cyanhill
Solved it! Thank you all.

@COM8 COM8 closed this as completed Sep 23, 2020
COM8 added a commit that referenced this issue Oct 20, 2020
COM8 added a commit that referenced this issue Oct 20, 2020
blattersturm added a commit to citizenfx/fivem that referenced this issue Mar 21, 2021
This fixes LibertyM Steam verification.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants