My application gets to a part of my code on Win, but on Linux it doesn't. Can't figure out why.

I'm sending a GET request to my Node.js server from my C++ application using Microsoft's cpprest lib. I've managed to get the size of the content and a json response from the server on Windows, but when I try the same code on Linux (from another computer), my application doesn't get to the json portion of the code.

I can't seem to think of possibilities that explain why this could happen. It's not like the code doesn't work. I get to the part where I get the size of the content, but on Linux that's as far as it goes.

I'll include the code below and how I'm compiling on my Linux system. By the way, linux is running on a Raspberry Pi. Hope I explained myself well :S

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <cpprest/http_client.h>
#include <cpprest/json.h>           
#include <cpprest/uri.h>   

int main() {
	web::http::client::http_client client(U("http://192.168.1.115:656/api/test"));
	client.request(web::http::methods::GET).then([](web::http::http_response response) {
		if (response.status_code() == web::http::status_codes::OK) {

			auto bodyStream = response.body();

			size_t contentLength = response.headers().content_length();
			std::wcout << U("Content Length: ") << contentLength << std::endl;

				return response.extract_json();
		}
	}).then([](pplx::task<web::json::value> previousTask) {
                        // Linux Raspberry Pi system doesn't get here, but windows does.
			std::cout << "JSON" << std::endl;
	}).wait();

	while(true) {}
	return 0;
}

// Compile:
// $ g++ -std=c++11 main.cpp -o app -lboost_system -lpthread  -lcrypto -lssl -lcpprest 


I'm guessing it has to do with pplx::task, since it's a MS thing and not part of the C++, but I read its cross-platform.
Last edited on
Try changing line
 
}).then([](pplx::task<web::json::value> previousTask) {

to
 
}).then([](web::json::value j)) {
raschupkin that definitely worked! I was also reading the following article and following the examples:

https://msdn.microsoft.com/en-us/library/dd492427(v=vs.110).aspx

Only that the MS cpprest lib uses a cross platform version of ppl called pplx, but the examples work regardless.

Thanks again.
Topic archived. No new replies allowed.