On Tue, Feb 3, 2015 at 10:05 PM, Vipul Rastogi
<[email protected]> wrote:
> I am trying to retrieve json body from http response (below code) but
> ast_http_get_json method expects ast_variable which is probably list of
> headers. so question is how to I get this from client (or client->ser).
> Suggestions most welcome !
>
> res_http_websocket.c -> websocket_client_handshake_get_response()
>
> struct ast_variable temp;
> struct ast_json *body = ast_http_get_json(client->ser, &temp);
> ast_log(LOG_ERROR, "After get json");
> struct ast_json *field = ast_json_object_get(body, "sid");
> ast_log(LOG_ERROR, "After get sid");
> if (field) {
> ast_log(LOG_ERROR, "received sid=%s",ast_json_string_get(field));
> }
>

The headers are provided used by that function are typically provided
in an ast_http_callback. Functions wanting to use ast_http_get_json to
extract a JSON body should pass the provided headers into the
function. Since these functions are specific to the HTTP server, they
were never envisioned being used by the websocket client code.

Since websocket_client_handshake_get_response is parsing out the HTTP
headers itself, you will need to store those in an ast_variable list,
and then attempt to call ast_http_get_json to pull out the JSON body.

That being said, I'm not sure why a server would be sending back a
JSON body during a handshake. What are you trying to implement? If
you're attempting to handle a JSON body passed to the websocket on the
initial connection attempt, what are you trying to extract, and why?

-- 
Matthew Jordan
Digium, Inc. | Engineering Manager
445 Jan Davis Drive NW - Huntsville, AL 35806 - USA
Check us out at: http://digium.com & http://asterisk.org

-- 
_____________________________________________________________________
-- Bandwidth and Colocation Provided by http://www.api-digital.com --

asterisk-dev mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-dev

Reply via email to