Read system.net.httpPost TOKEN

Good afternoon,
I'm calling a huawei solar system with API using this code

# Real time data
token = "myToken"

url = "https://eu5.fusionsolar.huawei.com/thirdData/getStationRealKpi"
payload = { "stationCodes":"xxxx" }
header = { "XSRF-TOKEN":token  }

response = system.net.httpPost( url, contentType='application/json; charset=utf-8', postData=system.util.jsonEncode(payload), headerValues = header, bypassCertValidation = True )
res_RealTime = system.util.jsonDecode(response)

My problem is that I have to log in and read the token that is present in the cookies. With POSTMAN I can read it without problem as in picture

but with this code

url = "https://eu5.fusionsolar.huawei.com/thirdData/login"
payload = {"userName": "myUser","systemCode": "myCode"}

response = system.net.httpPost( url, contentType='application/json; charset=utf-8', postData=system.util.jsonEncode(payload), bypassCertValidation = True )

print response

I don't know how to read that because I don't have it in the response.

Thanks for the help

Using system.net.httpClient instead, you should be able to get a response object, which has a getHeaders method.
You should be able to retrieve cookies from the headers.

2 Likes

Thanks for the help.

If can be useful this is how I make it work

client = system.net.httpClient(bypass_cert_validation=True)
res = client.post("https://eu5.fusionsolar.huawei.com/thirdData/login",data = {"userName": "myUser","systemCode": "myCode"})
tmp = res.getHeaders()
token = tmp['xsrf-token'][0]