HTTP post and wininet - c++

I implement sending POST request by using the wininet library. I tried to use the different flags both in the HttpOpenRequest and in the PostInitWinInetHandle functions. The generated request contains the Cache-Control: no cache header always.
Does HTTP protocol allows sending POST request without this header? If so how can I eliminate adding this header to a request?

Don't use the flag INTERNET_FLAG_PRAGMA_NOCACHE.

Related

How to request with request header to https URL using C++ REST SDK?

I'm trying to make source that requests to specific https URL with request header using c++ rest sdk.
ex)https://111.0.0.1:1111/vl/api/auth
Then, I want to allocate response value to char* value and print.
It is first time to use rest sdk. So I searched many things.
But,there are no solutions request 'Get' with request header
RequestHeader is like this :
id:"1234567890"
auth:"7d8ffbecb05d59459f96d6e3aac8542e"
But I don't know what to do
httpclient client(U("http://localhost:9991/test"));
////then How???
I need your help!
all you need to do like
http_request request(methods::GET);
request.headers().add(L"id", L"1234567890");
request.headers().add(L"auth", L"7d8ffbecb05d59459f96d6e3aac8542e");

Is it acceptable to have multiple `set-cookie` headers in an HTTP/2 stream?

I'm proxying HTTP/2 client -> HTTP/1.1 server, and I'm not sure how to handle multiple set-cookie in the response.
I believe set-cookie is the only header which is allowed to be set multiple times for HTTP/1.1 - is this the case for HTTP/2 as well?
If I receive set-cookie multiple times in the HTTP/1.1 response, how do I send that back to the client over HTTP/2? Can I merge it together into a single header, or do I need to send multiple set-cookie headers back via HTTP/2.0?
The HTTP/2 specification specifies how to handle cookies in this section.
It is the case for HTTP/2 as well that set-cookie is allowed to be set multiple times - its format would not allow otherwise.
A client receiving multiple set-cookie headers may send multiple cookie headers, or may concatenate them.
The server receiving multiple cookie headers must concatenate them
before invoking an application.

Mongoose Web Server HTTP Headers extremely slow

I have a mongoose server, with commands callable with AJAX. I get a CORS error if I call it without sending HTTP headers from mongoose (but visiting the address with the browser works just fine), but when I do send headers, it may take up to a minute before I get a response (but it does work), both with AJAX and the browser. My reply code:
//without headers
mg_printf(conn,reply.c_str());
//with headers
mg_printf(conn,"HTTP/1.1 200 OK\r\n"
"Content-Type: text/plain\n"
"Cache-Control: no-cache\n"
"Access-Control-Allow-Origin: *\n\n"
"%s\n", reply.c_str());
How can I speed this up? Am I sending my headers wrong?
Ok, I found a solution, it works if I first check whether the request is an api call or not, and only send the headers when it is.
The reason mongoose is slow is because it waits for the rest of the content until it times out. And the reason it waits is because you do not set Content-Length, in which case the "end of a content" marker is when connection closes.
So the correct solution is:
Add Content-Length header with correct body length, OR
Alternatively, use mg_send_header() and mg_printf_data() functions, in which case you don't need to bother with Content-Length cause these functions use chunked encoding.

Get/Set cookies from qml

I am writting a client program. When I login, the server will send some cookies to me in the 'Set-Cookie' header field.
I need to get the cookies, because the rest of the request will need them.
I try to get the cookies with xmlhttprequest.getResponseHeader("Set-Cookie"), but failed.
I don't want to use C++, so could it be possible?
No, it is not possible without using C++.
Look at source code for QDeclarativeXMLHttpRequest::fillHeadersList() method. It particularly removes set-cookie and set-cookie2 headers, following w3c specs for XMLHttpRequest object. Specifically behaviour of getAllResponseHeaders method. That is:
Return all the HTTP headers, excluding headers that are a case-insensitive match for Set-Cookie or Set-Cookie2, ...

How to pack http request body using libcurl?

Is it possible to send requests using libcurl in gzipped form? How can I do that?