Skip to content

How do you submit a POST Parameter?  #28

Closed
@danielcaldwell

Description

@danielcaldwell

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:

web::http::http_request postTestRequest;

postTestRequest.set_request_uri( "/whatever" );
postTestRequest.set_method( web::http::methods::POST );

// create post parameters for the body (as json). 
web::json::value postParameters = web::json::value::array();

postParameters[ L"Parameter1" ] = web::json::value::string( L"Test1" );
postParameters[ L"Parameter2" ] = web::json::value::string( L"Test2" );
postParameters[ L"Parameter3" ] = web::json::value::string( L"Test3" );
postParameters[ L"Parameter4" ] = web::json::value::string( L"Test4" );
postParameters[ L"Parameter5" ] = web::json::value::string( L"Test5" );

postTestRequest.set_body( postParameters );

// create a task
Concurrency::task<web::http::http_response> getTask = m_Client->request( postTestRequest );
... more code below... 

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 :

void operator()(_Ty *_Ptr) const _NOEXCEPT
    {   // delete a pointer
    static_assert(0 < sizeof (_Ty),
        "can't delete an incomplete type");
    delete _Ptr;  // <--- exception thrown here. 
    }
};

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions