Debug http.post

(4 posts) (2 voices)

Tags:

No tags yet.

  1. maron, Member

    Hello.

    Is there an option to add verbose debugging output of both the exact request and response for http.post

    I have managed to make a post request using CURL but can not make it properly in mydbr

    Maron

  2. maron, Member

    I'm trying to replicate this request in mydbr

    curl -d '{ "to": DEVICE_ID, "notification": { "title" : " This is my title new ", "body" : " This is the body of my message " } }' \ -i -H "Application/json" \ -H "Content-type: application/json" \ -H "Authorization: key=YOUR_AUTH_KEY \ -X POST https://fcm.googleapis.com/fcm/send

    This is my code


    select 'dbr.http.option','curl','CURLOPT_HTTPHEADER','Authorization: key=MYKEY';
    select 'dbr.http.option','curl','CURLOPT_HTTPHEADER','Content-Type: application/json';
    select 'dbr.http.post',
    'https://mydomain/dumppost.php', -- script that dumps post request to file
    "DEVICE_ID" as 'to',
    JSON_OBJECT('body', 'This is the body of my message', 'title', " This is my title new ", 'priority', 'low') 'notification'

    But what I get at the server is

    {"to":"DEVICE_ID","notification":"{\"body\": \"This is the body of my message\", \"title\": \" This is my title new \", \"priority\": \"low\"}"}

    I have tried I believe everything and cannot remove the backslashes from the notification object.

  3. myDBR Team, Key Master

    Maron,
    what you want to pass to the server is one JSON object where the notification property is also a JSON object (you should enclose the DEVICE_ID in quotation marks)

    In your myDBR version, you pass a JSON object where the notification property is a string (containing an encoded JSON).

    If you run the updater, you can use a new feature where you can POST a single JSON object. myDBR detects the content as JSON object if you give it an empty name:

    select 'dbr.http.option','curl','CURLOPT_HTTPHEADER','Content-Type: application/json';
    select 'dbr.http.option','curl','CURLOPT_HTTPHEADER','Authorization: key=MYKEY';
    select 'dbr.http.option','curl','CURLOPT_HTTPHEADER','Content-Type: application/json';
    select 'dbr.http.post', 'https://mydomain/dumppost.php',
    JSON_OBJECT('to', 'DEVICE_ID', 'notification', JSON_OBJECT('body', 'This is the body of my message', 'title', " This is my title new ", 'priority', 'low')) as '';

    --
    myDBR Team

  4. maron, Member

    Amazing - thanks - it works perfectly.


Reply

You must log in to post.