2

With the request:

curl -i -u pvserver:XXXXXXX 'http://192.168.2.42/api/login.json'

I have this output

{"salt":"uTxYWQDc9lWwsuHBRfkuTzJYG5M=","session":{"sessionId":2748768190,"roleId":0},"status":{"code":0}}

Now I want to send the following request to the server:

curl -X POST  \
  'http://192.168.2.42/api/dxs.json?' \
  -H 'accept: application/json, text/plain, */*' \
  -H 'accept-encoding: gzip, deflate' \
  -H 'accept-language: en-US,en;q=0.9' \
  -H 'authorization: Basic cHZzZXJ2ZXI6VjZUNUJYSDI=' \
  -H 'cache-control: no-cache' \
  -H 'content-type: text/plain' \
  -H 'cookie: language=en_GB' \
  -H 'origin: http://192.168.2.42' \
  -H 'referer: http://192.168.2.42/' \
  -H 'user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/71.0.3578.98 Chrome/71.0.3578.98 Safari/537.36' \
  -b language=en_GB \
  -d '{"dxsEntries":[{"dxsId":33556247,"value":95}]}'

which will work only if I include the received session ID, but I cannot copy and paste the ID as this is an automated process, part of a script, running every 6 seconds and getting the data "value" value from another server.

I have tried the curl -c and -b options but it appears to me they are not working as, using the browser development tool shows, the session ID does come in as a cookie.

2 Answers 2

0

I have solved this. Authentification on the first POST is sent as data. The two curl requests are:

curl -X POST \
  'http://192.168.2.42/api/login.json?sessionId=xxxxxxxxxx' \
   -H 'accept: application/json, text/plain, */*' \
   -H 'cache-control: no-cache' \
   -H 'content-type: application/json' \
   -H 'origin: http://192.168.2.42' \
   -H 'user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/73.0.3683.75 Chrome/73.0.3683.75 Safari/537.36' \
   -d '{"mode":2,"userId":"xxxxxxx_x","pwh":"xxxxxxxxxxxxxxxxxxxxxxxxxx="}'

and

curl -X POST \
  'http://192.168.2.42/api/dxs.json?sessionId=xxxxxxxxx' \
  -H 'accept: application/json, text/plain, */*' \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/json;charset=UTF-8' \
  -H 'origin: http://192.168.2.42' \
  -H 'user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/73.0.3683.75 Chrome/73.0.3683.75 Safari/537.36' \
  -d '{"dxsEntries":[{"dxsId":33556252,"value":3},{"dxsId":33556249,"value":50},{"dxsId":83888896,"value":1},{"dxsId":83888640,"value":true},{"dxsId":33556484,"value":false},{"dxsId":33556239,"value":0},{"dxsId":33556240,"value":82800},{"dxsId":33556247,"value":95}]}'

Both were obtained by copying as Curl using a browser development tool whilst clicking the UI relevant pages. Keeping whatever sessionId, userId and pwh values thus obtained ensures the commands will go on working. sessionId has to be the same on both Posts. It also turned out I had, in the second Post, to send all string values and not only the one which has to be updated.

0

The basic way to keep session state, is by using cookies:

curl -d '...' -b ~/.cache/mycurl.cookiejar -c ~/.cache/mycurl.cookiejar ...

Then you can cut some headers that is not needed anymore

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .