Sunday 27 August 2023

ASP.NET_SessionID fetched from set-cookie response header using python script does not work, while ASP.NET_SessionID fetched from browser does

Here is the goal, I am trying to get ASP.NET_SessionID using python request and then want to use it for further requests. I have been able to get the ASP.NET_SessionID from one of the requests that is setting it within the set-cookie in response headers, however when I make a subsequent request with that ASP.NET_SessionID, it does not work correctly the response is 200 but the response data is not accurate, the response data is the default data that returns for the expired session.

Here is the code for getting the ASP.NET_SessionID, I am using session as it automatically takes care of the cookies:

################### get asp session from set-cookie in response headers
url = "https://finder.humana.com/finder/v1/pfp/get-language-selectors"

response=session.get(url, timeout=20)

print(response, url)
jsonResponseHeaders = response.headers
aspSession = jsonResponseHeaders['Set-Cookie'].split(';')[0]
cookies=session.cookies.get_dict()
print(response.headers)
print('ASP.NET_SessionID:',aspSession)
print(session.cookies.get_dict())
cookieString = "; ".join([str(x)+"="+str(y) for x,y in cookies.items()])
print('Cookie String:',cookieString)

Here is the subsequent request:

################# provider plan/network request
url = "https://finder.humana.com/finder/v1/pfp/get-networks-by-provider"        

payload = {"providerId":311778,"customerId":1,"coverageType":3}     

response = session.post(url, json=payload)

print(response,url)
print(response.headers)
print(session.cookies.get_dict())
cookies=session.cookies.get_dict()
cookieString = "; ".join([str(x)+"="+str(y) for x,y in cookies.items()])
print('Cookie String:',cookieString)
print(response.text)
print()

The part I do not understand is that the ASP.NET_SessionID I get from the browser works fine within postman or python requests when I send it within cookie in headers, however which I get from python requests does not work.



from ASP.NET_SessionID fetched from set-cookie response header using python script does not work, while ASP.NET_SessionID fetched from browser does

No comments:

Post a Comment