Sending a POST request from the Server

Sep 29, 2014 at 5:42 PM
I am using this code to POST a string from a webpage to a C++ listener application using REST SDKs.

This is the code from the webpage
$.ajax({
          url: "http://localhost:2001/",
          dataType: "json",
          type:"post",
          data: {Name:"Roschuma"},
          success: function (data) {
              console.log(data);
          }
      });
And this is the code in console application.
listener.support(methods::POST, [](http_request req)
{
    std::cout << "Serving POST" << std::endl;
    req.extract_string(true).then([req](utility::string_t body)
    {
        std::wcout << body << std::endl;
        req.reply(status_codes::OK, U("<html><body>Received.</body></html>"), U("text/html"));
    });
});
Now I have to do the reverse POST some value from the C++ application into the webpage. How can I accomplish this?
Oct 1, 2014 at 8:27 AM
Or in short I want my Listener application to Postback to the webpage. How can I accomplish this?
Coordinator
Oct 1, 2014 at 5:20 PM
Hi maverick786us,

I'm confused on exactly what you are asking for. I don't have a lot of experience with html forums. The listener or server can send back whatever data in the response body. In your code snippet you are sending a simple string with HTML.

I recommend you take a look online at some other resources for more information. Here are a couple of questions on stackoverflow about PostBacks

http://stackoverflow.com/questions/4251157/what-is-a-postback
http://stackoverflow.com/questions/183254/what-is-a-postback

Steve
Oct 7, 2014 at 7:00 AM
Edited Oct 7, 2014 at 8:10 AM
This part.
listener.support(methods::GET, [](http_request req)
    {
        std::cout << "Serving GET" << std::endl;
        req.reply(status_codes::OK, U("<html><body><h1>It works!</h1>(Casablanca, that is a GET Request.)</body></html>"), U("text/html"));
    });
This thing that I am sending using req.reply, I want the user to input that thing. I know what PostBack is, all I want was the listener to PostBack to the page, just like the way IIS does.
Coordinator
Oct 7, 2014 at 4:27 PM
If you want the response data to come from the user's HTTP request they you will have to send the information through headers or the request body. I'm not sure of another way that the user can enter data to your service. The data could also come from some other external source you might have, like a database, etc....

Steve