Answer the question
In order to leave comments, you need to log in
How to truncate header in https response?
comes this answer
HTTPS/1.1 200 OK
Content-Type: application/json; charset=utf-8
Content-Length: 48
Connection: Close
{
"DATA": {
"ERROR": "ANY USER IS LOGIN"
}
}
do {
char buf[1024] = "\0";
size_t bytes_transferred = sock.read_some(boost::asio::buffer(buf), ec);
if (!ec) response.append(buf, buf + bytes_transferred);
} while (!ec);
Answer the question
In order to leave comments, you need to log in
in boost is almost the same
#include <iostream>
#include <algorithm>
#include <iterator>
using namespace std;
int main()
{
char buf[1500]{"HTTPS/1.1 200 OK\nContent-Type: \
application/json; charset=utf-8\n\
Content-Length: 48\
Connection: Close{\"DATA\": {\"ERROR\":\
\"ANY USER IS LOGIN\"}}"};
auto bs{ find(begin(buf) , end(buf) , '{' ) };
auto es{ find(rbegin(buf), rend(buf) , '}' ) };
copy(bs, es.base(), ostream_iterator<char>(cout));
}
{"DATA": {"ERROR": "ANY USER IS LOGIN"}}
delete everything from the zero byte up to and including the first line break, or use the functions of the library, which is sharpened to work with http.
#include
#include
#pragma warning(disable:4996)
Int main(){
char request[256]; char*p; intn=0;
// remove GET from the request string
// with this content
// GET/home.html/HTTP/1.1
//trace function returns the index of the first
// element specified in the second arg
p = std::strstr(request, “/home ”);
//calculate the number of characters before “home”
n = p -request;
//write n-zeroes into the string
std::strncpy(request, “\0”, n);
// home.html/HTTP/1.1 remains in the string // get
rid of the "tail"
p = std::strstr(request , “/HTTP “);
n = p - request;
chartemp[256]; char*pt = temp;
std::strncpy(pt, request, n);
//insert zero into con
str temp[n]='\0'; n++;
//everything
//in the temp page remains home.html
return 0;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question