-
Notifications
You must be signed in to change notification settings - Fork 947
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
HTTP Error 411 while making POST request to Microsoft Azure Workspace #377
Comments
Arg... Thanks for reporting this. |
Hey @COM8. Thanks for the response. Could you give an estimated timeline as till when this issue might be resolved? This library being so simple to use, has become important for our project. An estimate would help me plan the project further. Thanks. |
@PatronusCoder I would say by the end of next week. |
For validation could you please come up with a simple test case, where this error occurs, please? This would help a lot! |
I'll try it today and definitely try to work out a simple test case. Thanks! |
Hey @COM8. That commit did not solve the issue. |
Hey @COM8. Found another thing interesting which might be helpful. When I pass the authorization signature as an lvalue, then the Postman-echo service does not show the body. However, if I pass it as an rvalue (generated a key for a future time and then made post request), it worked fine. |
@PatronusCoder this could be an interesting one since using Header = std::map<std::string, std::string, CaseInsensitiveCompare>; |
In your example from above, you are never setting the |
Hey @COM8. I made the change in the code above. It was typo so thanks for that. Also, I couldn't generate a minimal example. The authorization key signature is dynamically generated and that is where it doesn't work. Therefore I could not make a minimal example for this issue. The code above was actually built as a minimal example for testing. |
I'm still unable to reproduce this bug. static std::string getTimestamp() {
char buf[1000];
time_t now = time(0);
struct tm* tm = gmtime(&now);
strftime(buf, sizeof buf, "%a, %d %b %Y %H:%M:%S GMT", tm);
return buf;
}
TEST(UrlEncodedPostTests, PostReflectTest) {
std::string uri = server->GetBaseUrl() + "/reflect_post.html";
std::string body = "{\"property1\": \"value1\"}";
std::string contentType = "application/json";
std::string signature = "x-ms-date: something";
std::string logType = "LoggingTest";
std::string date = getTimestamp();
auto response = cpr::Post(cpr::Url(uri),
cpr::Header{{"content-type", contentType},
{"Authorization", signature},
{"log-type", logType},
{"x-ms-date", date},
{"content-length", std::to_string(body.length())}},
cpr::Body(body));
EXPECT_EQ(ErrorCode::OK, response.error.code);
EXPECT_EQ(200, response.status_code);
EXPECT_EQ(body, response.text);
EXPECT_EQ(std::string{"application/json"}, response.header["content-type"]);
EXPECT_EQ(signature, response.header["Authorization"]);
EXPECT_EQ(logType, response.header["log-type"]);
EXPECT_EQ(date, response.header["x-ms-date"]);
EXPECT_EQ(std::to_string(body.length()), response.header["content-length"]);
} So I don't this this is a fault of |
Found the problem. The |
I am trying to set up a remote log system on the Microsoft Azure Workspace. I am using cpr POST request to send sample JSON data over to the server. The code I used is as follows:
However, I'm always getting the same error like this (from response.text) :
Things I have tried and the results:
3.1 Sending JSON data with authorization header:
Notice that even though I'm sending JSON data with the POST request, Postman-echo does not show it. This is strange because when I did the same thing using a Python script, the result showed me both the data as well as the authorization signature.
3.2 Sending JSON data without authorization header:
Then Postman-echo is showing me the json data sent.
In my understanding, generated key is not wrong, since in that case, authorization failure is the first error. The same code above, written in Python3 and Python2 worked correctly. This was the link I was following: https://docs.microsoft.com/de-de/azure/azure-monitor/platform/data-collector-api
Is there any known issue of similar kind in the cpr library? Please help.
The text was updated successfully, but these errors were encountered: