Click here to Skip to main content
15,886,919 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I am Trying this code..but it is not properly executing..Please Help me..

C++
#include <cpprest/http_client.h>
#include <cpprest/filestream.h>
#include <cpprest/http_listener.h>             
#include <cpprest/json.h>                      
#include <cpprest/uri.h>                                      
#include <cpprest/containerstream.h>            // Async streams backed by STL containers
#include <cpprest/interopstream.h>              // Bridges for integrating Async streams with 
#include <cpprest/rawptrstream.h>               // Async streams backed by raw pointer to 
#include <cpprest/producerconsumerstream.h>     // Async streams for producer consumer 
#include <iostream>
#include <sstream>

using namespace std;
using namespace utility;                    // Common utilities like string conversions
using namespace web;                        // Common features like URIs.
using namespace web::http;                  // Common HTTP functionality
using namespace web::http::client;          // HTTP client features
using namespace concurrency::streams;       // Asynchronous streams
using namespace web::http::experimental::listener;

int sample1()
{
	int A1, A2;
	cout << "Enter the Number1 ";
	cin >> A1;
	cout << "Enter the Number2 ";
	cin >> A2;
	int sum1 = A1 + A2;
	return sum1;
}

int main(int argc, char *args[])
{
	// Client side process
	http_client client(L"http://localhost:8080/sum1");
	client.request(methods::GET).then([](http_response response)
	{
		if (response.status_code() == status_codes::OK)
		{
			auto body = response.extract_string().get();
			wostringstream ss;
			ss << L"Server returned status code " << response.status_code() << L"." << std::endl;
			std::wcout << ss.str();
			//sample1();
			std::wcout << "SUM of Addition Result = " << body << endl;
			getchar();
		}
	});

	//server side  process
	http_listener listenerVoices_1(L"http://localhost:8080/sum1");
	listenerVoices_1.support(web::http::methods::GET, [](web::http::http_request request)
	{
		int sum1 = sample1();
		request.reply(web::http::status_codes::OK, sum1);
	}
	);
	listenerVoices_1.open().wait();
	std::string line;
	std::cout << "Press enter to exit" << std::endl;
	std::getline(std::cin, line);

	listenerVoices_1.close().wait();

	getchar();
	return 0;
}
Posted
Comments
Richard MacCutchan 12-Jun-14 6:47am    
What does "not properly executing" mean?
[no name] 12-Jun-14 6:51am    
What error are you exactly getting?
Member 10419043 12-Jun-14 6:56am    
it is not running at dynamically..
[no name] 12-Jun-14 7:21am    
That means nothing at all to us. You need to learn how to debug your code.

1 solution

Your sample function is waiting for input from the command line.
But you are trying to service a web-request. This sample function will never return because no one is at command line to press Enter.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900