If not timeout, then possibly copy & paste (or parsing) error. Run tcpdump to see if your program is sending a correct token.
If not parsing bug, then possibly you didn't get the token at all. Check the response status code and json data.
Try manually first as below.
Get a token:
curl -sk https://mgmtPort/mgmt/shared/authn/login -X POST -H "Content-Type: application/json" \
-d '{"username":"admin", "password":"secret", "loginProviderName":"tmos"}'
Output (abridged):
{"username":"admin",
...
"token": {
"token":"3YJFTKX4434X5ZZ7LGBPS5CAVA",
"name":"3YJFTKX4434X5ZZ7LGBPS5CAVA",
...
},
"timeout":1200, <<< seconds (=20 min)
"startTime":"2017-07-05T13:42:47.103+1200",
...
}
Use the token (let go, Luke):
curl -sk -H "X-F5-Auth-Token: 3YJFTKX4434X5ZZ7LGBPS5CAVA" \
https://mgmtPort/mgmt/tm/sys/version
When you've got a wrong token:
curl -sk -H "X-F5-Auth-Token: 3YJFTKX4434X5ZZ7LGBPS5CA" \ <<< forgot the last two chars.
https://mgmtPort/mgmt/tm/sys/version
Output
{"code":401,"message":"X-F5-Auth-Token does not xist.", ...}
You can check the available tokens on the system as below:
curl -sk -H "X-F5-Auth-Token: 3YJFTKX4434X5ZZ7LGBPS5CAVA" \
https://mgmtPort/mgmt/shared/authz/tokens | python -m json.tool | grep \"token\"
Output:
"token": "3YJFTKX4434X5ZZ7LGBPS5CAVA",