-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
How do you submit a POST Parameter? #28
Comments
JSON: I think you want to use a json object instead of an array. While json array is an ordered sequence of values, json object contains key/value pairs. So here, to create an object you want to do something like:
For arrays, we provide the index operator:
We dont provide the add(), push_back() functions directly on a json value but you could use the array constructor that takes a vector. Similarly use a vector of std::pair<string_t, json::value> for a json object.
I recommend using our JSON tests for reference, in this case: construction tests HTTP_REQUEST Let us know if you have any further questions. |
Okay, for anyone else who tries to submit a post request there are two things that I found. Your servers may be configured differently. Problem 1: I tried to use JSON and that won't work. I was only able to get it working using a string which I constructed like this:
Problem 2: JSON won't work because I had to overwrite the ContentType header to "application/x-www-form-urlencoded" so it was like a form was being submitted. Your server may be configured differently and can parse out the body of a POST request if the content type is plaintext or json.
RestSharp (http://restsharp.org/) is a good REST library for C#. I created a simple post request there to see how it used it's lower level libraries to submit a request. After stepping through how it handles the post request, I noticed the content type was being changed and that's was the key to getting it to work. Specifically here: https://github.com/restsharp/RestSharp/blob/master/RestSharp/Http.cs#L356 @kavyako thanks for your feedback. I've changed the name of this issue to reflect the actual question I had. Hopefully it will help others find it if they are struggling to figure out how to use this library to do a simple POST request. |
I am facing same issue. I am unsure about the best way to make a simple POST request (no JSON) with post parameters. Especially, one with big file as one of the parameters. I tried creating the
But this just gives me |
I am facing a similar issue to this, and getting a response code of 429. This is the code I'm using:
I'm stuck on what piece I'm missing here. |
@aawiesinger You can add url query parameters via creating a uri. Here is the sample code. auto query_params = {{"ipd" : "5"}, {"key": "value"}};
auto uri = web::http::uri_builder(endpoint_path);
for (auto const& param : query_params)
{
uri.append_query(param.first, param.second, true);
}
web::http::http_request request(method);
request.set_request_uri(uri.to_uri()); |
What is the correct way to do this? I am getting errors on all the above approaches. Mainly this error Trying to do this:
Number does not error |
All json values are wstrings. So, try json_v[L"title"] = web::json::value::string(wide_string); |
I'm creating a JSON array for adding POST parameters to a request.
This is an example of the code I see as the example of how to do this:
When I run it, I get an access violation exception thrown. Obviously I'm missing something simple here but for the life of me I can't see it. The first exception thrown is here:
https://github.com/Microsoft/cpprestsdk/blob/master/Release/include/cpprest/json.h#L1427
Continuing from that it will break here:
c:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\memory :
I can't continue from that point as it will continually break there.
Also, in the array, I don't see an add(), push_back(), insert(), or any other function that looks like it can add things to these arrays. Any help would be great as I'm stepping through debugging things and the debugger doesn't let me move beyond this point. Even if you continue, it keeps breaking there. I'm using VS 2013.
I don't really care if the body is JSON or whatever, just trying to add some parameters to the post request. However in the requests object I don't see a helper function for adding parameters or anything useful like that.
The text was updated successfully, but these errors were encountered: