Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http_request support POST JSON ? #114

Closed
lxlenovostar opened this issue Mar 6, 2018 · 1 comment
Closed

http_request support POST JSON ? #114

lxlenovostar opened this issue Mar 6, 2018 · 1 comment

Comments

@lxlenovostar
Copy link

I know websock_send support send a JSON data like this:
EOR(websock_send(client->ws_connection, WEBSOCK_TEXT, "%H", json_encode_odict, dict));

So I want use http_request send a JSON data in this way:

 {
            (void)re_snprintf(url, sizeof(url),"http://101.69.114.92:%u/report/", 80); 
       
            struct odict* post_dict;
            EOR(odict_alloc(&post_dict, 16));

            char type[16] = "play-interval"; 
            char customid[128] = "google.cn";
     
            EOR(odict_entry_add(post_dict, "0017", ODICT_STRING, type));
            EOR(odict_entry_add(post_dict, "0009", ODICT_STRING, customid));

            //Test POST 
            err = http_request(&req, cli, "POST", url, http_resp_handler, NULL, &t, "%H", json_encode_odict, post_dict);
            if (err) {
                DEBUG_PRINTF("exit\n");
                goto out; 
            }
        }

This produce a wrong tcp packet.
_030618_103747_am

Does I use the wrong method of http_request ?

Thank you.

btw: I can't find example of http_request(POST) in retest, rawrtc and libre,

@richaas
Copy link
Contributor

richaas commented Mar 6, 2018

The http_request fmt argument takes both headers and body. Example usage:

http_request(...,
	     "Content-Type: application/json\r\n"
	     "Content-Length: %zu\r\n"
	     "\r\n"
	     "%s",
	     str_len(body), body);

@richaas richaas closed this as completed Mar 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants