2
votes

I'm trying to send a HTTP request to a server via boost asio. I have the following request that I have created in c++:

static const std::string TEMPLATE_HEADER =
"POST " + HTTP_PATH + " HTTP/1.1\r\n"
"Content-Type: application/json\r\n"
"Host: " + HOST_TAG + "\r\n"
"{ " + TEMPLATE_BODY + " }\r\n\r\n";

The actual request that i am sending on is this:

POST /eikon/authsession/machines/ HTTP/1.1 Content-Type: application/json Host: amers1.am.cp.icp2.mpp.ime.reuters.com:80 { "machineID" : "EP-03A482F1B88A","password" : "PasswordReset","takeESOControl" : "false","deviceID" : "123" }

This works when using Postman (a Google Chrome extension), but this doesn't seem to work using boost asio. I do the following (the above HTTP Request is strTemp.

// Write the request to the buffer
size_t request_length = strTemp.length();
boost::asio::write(s, boost::asio::buffer(strTemp, request_length));

char reply[max_length];

// When a reply is received ending in the correct tag we are looking for, store it in the response buffer
boost::asio::streambuf response;
boost::asio::read_until(s, response, Constants::BRACE_TAG);

Where the BRACE_TAG variable = "}" (as the response returned ends with a curly brace.

I get an exception come back that says "Exception: read_until: End of file".

Anyone have an idea what's happening?

Thanks.

1
This question is exactly the same as your question posted 6 hours ago. It's bad etiquette to repost your questions to get attention.sehe
I didn't get any answers for it in the space of 6 hours, yet posting it now I got an answer. It's deleted anyway - it would have been bad etiquette for me to have left it up and post again.Suzan Aydın
Note it was me who answered. And I even upvoted. I don't know why you're so upset. Oh, and I was answering the "old" version of your question, but then you deleted it.sehe

1 Answers

2
votes
  1. between the headers and the body there should be a double newline:

    "Host: " + HOST_TAG + "\r\n\r\n"
    
  2. You might be required to send a Content-Length header (What's the "Content-Length" field in HTTP header?). Postman might add it for you