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!
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.
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
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!