Skip to content
This repository was archived by the owner on Jun 1, 2026. It is now read-only.
This repository was archived by the owner on Jun 1, 2026. It is now read-only.

HTML Page Using Javascript to Access C++ REST Web Service? #77

@jameskennedy2265

Description

@jameskennedy2265

Apologies ahead of time if this is the wrong place to put this question, I didn't see a discussion place for general topics. I've also posted this over at the old C++ REST SDK page.

Hey All,

So I've spent about two weeks learning and creating my web service using C++ REST.

I've really liked it so far and I've actually got everything up and running I believe. Here is some of the code I am using which will process a simple GET request.

int main(int argc, char *argv[])
    {

    uri_builder uri(L"http://localhost:8888");          // This defines my URI location. example is http://localhost:8888/
    http_listener listener(uri.to_uri());              //this will create a listener at the given location of my defined URI above
    printf("HTTP LISTENER STARTED \n");


    // This is the part where the listener can handle GET requests
    listener.support(methods::GET, [](http_request request)         // this block causes the listener to support GET requests
        {                              // When pinged for a GET request it will do the following
        printf("GET Request\n");    
        int status = 5;
        web::json::value statvalue = json::value::number(status);  //putting status into a json container
        printf("GET Request Finished \n");
        request.reply(status_codes::OK, statvalue);

}

This handles an incoming GET request and will output the value 5 if completed. I've tested this using TELNET to connect to the webservice and I used a generic GET request

GET /test HTTP/1.1
Host: localhost

in order to show that it all works out.

Now I am trying to create an HTML web page that will perform a GET request to my webservice.

So far I've been unable to perform this. Below is what my HTML page is looking like

<html>

<head>
    <title>GET TEST</title>

        <script language="JavaScript">

            var iCallID;
            function InitializeService()
            {
                service.useService("http://localhost:8888/",  "httprequestservice");
                service.httprequestservice.callService("http_request");
            }

            function ShowResult()
            {
               alert(event.result.value);
            }

        </script>

        <meta http-equiv="refresh" content="5" />
</head>

    <body  onload="InitializeService()"  id="service" style="behavior:url(webservice.htc)"  onresult="ShowResult()">

    </body>

</html>

What am I doing wrong? Is there an example somewhere that someone could show me how to access this websebservice using an HTML page?

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions