You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi,
I'm trying to implement two HTTP POSTs: one containing some file data (application/octet-stream) and another posting a simple JSON (application/json).
Anyone could provide a sample?
The text was updated successfully, but these errors were encountered:
There's the comment in the example that said first response is always empty, nothing was sent yet... right before the http_finish would be where you would want to set any headers.
If you want to send a second request, set new headers and send another request... just make sure to somehow be able to test for the response cycle (you could simple change the callback used to rotate callbacks according to state).
I'd like to focus first in a simple client POST with JSON. I believe that when I get it working I'll manage to use octet-stream. The json structure is as simple as:
{"userId":"1", "message":"test"}
What did you try? where are you stuck?
I've sucessfully implemented a client GET as follows:
Then I read the response on on_http_response . It was based in your samples and the documentation.
static void on_http_response(http_s *h) {
if(h->status_str == FIOBJ_INVALID){
//ignore the first empty response
http_finish(h);
return;
}
http_parse_body(h);
FIOBJ obj = h->body;
fio_str_info_s raw = fiobj_obj2cstr(obj);
fprintf(stdout, "Fingerprint received - size = %d\n", raw.len);
data = fp_print_data_from_data((unsigned char *)raw.data, raw.len);
fiobj_free(obj);
//continue with some processing...
}
For the aforementioned client GET, the parameter is already set on http_connect, so I was wondering if for a client POST it would be similar (maybe build a FIOBJ and set it on http_connect...).
If I understood you well, your suggestion ins that I should call http_connect without any parameter, then somehow set the POST json parameter from inside on_http_response (before http_finish), that is correct?
Hi,
I'm trying to implement two HTTP POSTs: one containing some file data (application/octet-stream) and another posting a simple JSON (application/json).
Anyone could provide a sample?
The text was updated successfully, but these errors were encountered: