T
T
Tesla4o2018-10-03 15:49:56
JSON
Tesla4o, 2018-10-03 15:49:56

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"
 }
}


How can I leave only json?
I get the answer like this

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

3 answer(s)
R
Roman, 2018-10-03
@Tesla4o

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"}}

V
vreitech, 2018-10-03
@fzfx

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.

A
Alex Other planet, 2018-10-11
@BadElectrician

#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 question

Ask a Question

731 491 924 answers to any question