How can I transform curl command to apply to RESTful Sensor

hi,

I can use CURL output as the correct JSON result

curl 'http://192.168.1.11/ajax/fetch.php' \
  -H 'Cookie: PHPSESSID=gt5ffbsd8d645jghj456' \
  --data-raw 'selected_method=list_devices&selected_group=Devices&selected_output_method=json'

Now I want to use RESTful Sensor to apply to HA:

  - platform: rest
    name: device_list
    resource: http://192.168.1.11/ajax/fetch.php
    json_attributes_path: "$.data.0"
    value_template: "OK"
    json_attributes:
      - "state"
    verify_ssl: false
    headers:
      Cookies: PHPSESSID=gt5ffbsd8d645jghj456
      data-raw: selected_method=list_devices&selected_group=Devices&selected_output_method=json

this is not working.I don’t see any json results in the properties of sensor.device_list. I make sure that the “headers” part is not written correctly, caused the JSON output to be incorrect. what should be the correct way to write it?

BTW: if I use Command line Sensor to do this,I know how to do and successful testing.

thanks

Curl’s “data-raw” is used to send the data body for a PUT or POST method, normally
By default, curl is using GET, and a GET does not have a data body.

Not sure what curl is actually doing here, you might add “-v” to have the details.
Anyway, adding “data-raw” to the headers is wrong.

curl 'http://192.168.1.11/ajax/fetch.php' \
  -H 'Cookie: PHPSESSID=gt5ffbsd8d645jghj456' \
  --data-raw 'selected_method=list_devices&selected_group=Devices&selected_output_method=json'

and

curl -X POST 'http://192.168.1.11/ajax/fetch.php' \
  -H 'Cookie: PHPSESSID=gt5ffbsd8d645jghj456' \
  --data-raw 'selected_method=list_devices&selected_group=Devices&selected_output_method=json'

The results are all correct for the JSON content I want.

is there any way to handle body data in “platform: rest” ? What parameter should be used?

Would be:

  - platform: rest
    name: device_list
    resource: http://192.168.1.11/ajax/fetch.php
    method: POST
    payload: "selected_method=list_devices&selected_group=Devices&selected_output_method=json"
    json_attributes_path: "$.data.0"
    value_template: "OK"
    json_attributes:
      - "state"
    verify_ssl: false
    headers:
      Cookies: PHPSESSID=gt5ffbsd8d645jghj456

Unfortunately, it doesn’t work
I think maybe the problem is the way it is handled here