hightman/httpclient

Cookies not working in post method

Closed this issue · 6 comments

Remote login in website and saved cookies. After that saved cookies not working in post method. But working in get method. After logged in i have to send post request in same website another url.

May be your post request $http->post() code have not cookies codes. I am getting 403 forbidden error.

There is not difference for applying cookies, whether it is GET or POST, or other HTTP methods.
Please check your request URL and path of cookie, are they matched?

The following code works well.

$http = new Client();
$http->get('http://d9.sunbo.com/~hightman/ip.php');
$http->post('http://d9.sunbo.com/~hightman/ip.php');

Everything is okay... I tried many times but not working... May be all cookies not saving. Cookies collecting and saving have problem.

Please update this function: fetchCookieToSave() to collect all cookies.

Its also part of my header request.
$http->setHeader('x-requested-with', 'XMLHttpRequest');

Post request: $http->post($url, $arrayPostField);

In debug i got: ssl://ip:443 after visit this ip port i getting 400 error.

All cookies not colleting. Curl collecting all cookies and working in curl. I compared both cookies, saw that 2-3 line is missing.

How will i get all cookies like curl cookie without array?

Its your code cookies (old):

Array
(
    [www.fiverr.com] => Array
        (
            [/] => Array
                (
                    [_pxhd] => Array
                        (
                            [value] => Ahb8ItRUidqb/iRZWGBcZPXz14hVaU8STkWHBGs/W9Z6BdlNNyLEa8hTVx6pdtUBOYBrmb6ZBvaxk7dPWQyKXw==:KpQdKL-X6KkpEBTK96lun-mUaWVTiWJWSfgVdOyzNL4kbrdinSWlhVIy5Br9ZlLLws09Chw-RTnjuxQQbGsiq5UDlj4acEj/deSs1Hp172w=
                            [expires] => 1666787155
                        )

                    [_fiverr_session_key] => Array
                        (
                            [value] => 1cb52c60cbb10c753b8dce7c9cbf13e1
                            [expires] => 1635855956
                        )

                    [first_page_after_registration] => Array
                        (
                            [value] => true
                            [expires] => 1635251216
                        )

                )

        )

    [fiverr.com] => Array
        (
            [/] => Array
                (
                    [u_guid] => Array
                        (
                            [value] => 1635251151766-1f0d7b5c-6f62-4e83-a7ae-5ee5c2bf21eb
                            [expires] => 1666787151
                        )

                    [logged_out_currency] => Array
                        (
                            [value] => BRL
                            [expires] => 
                        )

                    [page_views] => Array
                        (
                            [value] => 1
                            [expires] => 1637929551
                        )

                    [visited_fiverr] => Array
                        (
                            [value] => true
                            [expires] => 1635251456
                        )

                    [__cfruid] => Array
                        (
                            [value] => 37b39a7e24b95cf5f880ec0f95aa2d16586ece1f-1635251151
                            [expires] => 
                        )

                    [hodor_creds] => Array
                        (
                            [value] => eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE2NjY3ODcxNTYsImlzcyI6ImZpdmVyci9ob2Rvci92MiIsInVpZCI6MTE2MTExNDI0LCJ1cHMiOiJiMzBjN2RjOTUyMzEwZmY2MmYzZTBlNTdiNjRiNmUxYTcxZTA0ZjhmODMxNDE5OTZlZjgyMDRmNDI1OTBlN2FjZWJjYjFiMzU3MTFkNzVkOTc1Njc4ZTE4MjRjMGE2MjAzNGM3ZGZiMzlmMmE3ZDFhODdhNWQwYWVmNWM1NjNmNiIsImlhdCI6MTYzNTI1MTE1Niwic2lkIjoiODZjYzM5YzY5ZjY0ZWNjMWU0YjA3M2I4NWMzNTg0YWEifQ.6rySv5UjIlz1Q_ZNtcC_MDzwESBX7LwOIIOrWZIV0Hk
                            [expires] => 1666787156
                        )

                    [logged_in_currency_v2] => Array
                        (
                            [value] => BRL
                            [expires] => 
                        )

                    [session_locale] => Array
                        (
                            [value] => en
                            [expires] => 
                        )

                )

        )

)

New cookies:

a:2:{s:14:"www.fiverr.com";a:1:{s:1:"/";a:3:{s:5:"_pxhd";a:2:{s:5:"value";s:197:"XyN1YKg1D9me3h6NXDCjEFwo5j3z4i0y-FYZ7xJSGcZ0QNl2O-xTB/Q1/v3-vBdauIb6vr3kNT3KazmqghPjOQ==:uvOciLgcSlruoN0hflyrXbhGqokt4VlWNwq2MYTDWbL1JBSvOyl7HxrJZ3CeXmdVNwTX7xqC955N/s4UFq/8khDVjHXJuOwOtzJBybpUAvI=";s:7:"expires";i:1666788788;}s:19:"_fiverr_session_key";a:2:{s:5:"value";s:32:"a6120cc3b597467eb6693e216cb2cc11";s:7:"expires";i:1635857588;}s:29:"first_page_after_registration";a:2:{s:5:"value";s:4:"true";s:7:"expires";i:1635252848;}}}s:10:"fiverr.com";a:1:{s:1:"/";a:8:{s:6:"u_guid";a:2:{s:5:"value";s:50:"1635252785181-d629b602-ed9b-4f20-b954-093cc72d6560";s:7:"expires";i:1666788785;}s:19:"logged_out_currency";a:2:{s:5:"value";s:3:"INR";s:7:"expires";N;}s:10:"page_views";a:2:{s:5:"value";s:1:"1";s:7:"expires";i:1637931185;}s:14:"visited_fiverr";a:2:{s:5:"value";s:4:"true";s:7:"expires";i:1635253088;}s:8:"__cfruid";a:2:{s:5:"value";s:51:"8bd2134a07ca955b5902c942a693f55de20612f2-1635252788";s:7:"expires";N;}s:11:"hodor_creds";a:2:{s:5:"value";s:419:"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE2NjY3ODg3ODgsImlzcyI6ImZpdmVyci9ob2Rvci92MiIsInVpZCI6MTE2MTEyNTM3LCJ1cHMiOiJkMzY1ZTNhMDU2ZjljZDQwZmJlOWZmZTUzNTM3MmFmNDc3MmRhZmNiMjliYmE4MDQyZDZmMmIyZWMzNDhhYzY4YzBhMWMyNWE3Y2NlYjEzZTJmNTY4YWNmMjhiZTY2M2UzNDYyMDZhOWVkN2QyYTIyOTFjZWM2NDk5NzM2MjU5NCIsImlhdCI6MTYzNTI1Mjc4OCwic2lkIjoiMTM1MmQ1ZmE0NGMwYmVlYjAyZWZkMTljOGJmMjY0Y2YifQ.FIO6lcwTAMW-7XsbAYg2qfoPBY1xuozTGMSo2-vu8OY";s:7:"expires";i:1666788788;}s:21:"logged_in_currency_v2";a:2:{s:5:"value";s:3:"INR";s:7:"expires";N;}s:14:"session_locale";a:2:{s:5:"value";s:2:"en";s:7:"expires";N;}}}}

Its curl cookies (many old):

# Netscape HTTP Cookie File
# https://curl.se/docs/http-cookies.html
# This file was generated by libcurl! Edit at your own risk.

.fiverr.com	TRUE	/	FALSE	0	logged_in_currency_v2	USD
#HttpOnly_www.fiverr.com	FALSE	/	FALSE	1631124613	_fiverr_session_key	f5584ad8475b9b8ba61c1f241cccefcc
.fiverr.com	TRUE	/	FALSE	1630520112	visited_fiverr	true
.fiverr.com	TRUE	/	FALSE	0	session_referer	https%3A%2F%2Fm.facebook.com%2F
#HttpOnly_.fiverr.com	TRUE	/	FALSE	1662055811	hodor_creds	eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE2NjIwNTU4MTEsImlzcyI6ImZpdmVyci9ob2Rvci92MiIsInVpZCI6MTEzMzM0MjUyLCJ1cHMiOiI3MTEzZGI0OTM5M2FkODIxYjQ5OWVmZDQyOGRiNDY2ZDYzMGZiYTI1NTQwOTkxNjU5ODBmZDc0ZTZhYWFkMzdiNDY4MGNmOWVhOTNmMjgyNDI3ZDUzYTg3ZWQyNDIyZTViMTQxODY2YTIyNWE0YTdmZTY2YzZmYjYxZTAxNjI0YSIsImlhdCI6MTYzMDUxOTgxMSwic2lkIjoiYTU0NmRiZTk4MWQ4NDAyYjQyZDhhYjllODgwNTc2N2EifQ.bAPsk555Ccz8NY4nfL_LsN5BMJPzgGmBfQjb8eHhMNQ
.fiverr.com	TRUE	/	FALSE	0	logged_out_currency	USD
.fiverr.com	TRUE	/	FALSE	0	guid_ext	1630519811
.fiverr.com	TRUE	/	FALSE	1662055811	u_guid	1630519811911-e5f9a243-da4f-47bb-b9c8-c36473324240
www.fiverr.com	FALSE	/	FALSE	1662055812	_pxhd	CKsq5ulKU9OZU7sVGLQcfGwO6RKj5EPZRIJPVtitDBhltWvva/yhs7XZqyWHLZ3QvJRZ2WxAf7S/cdZoZ73G3A==:j6ydz-nEg--l730vgeiQZYQ8b1W1SO0h39jYhuj9OuLYm9d3fJtlm8SSrugZx3UWtcm2o6WrrqLoyrG5ZXPWxroZ20akHL2UGB6QJfus2kw=
#HttpOnly_.fiverr.com	TRUE	/	FALSE	0	__cfruid	eb5dc176a7654c59d39e2de1902ef3607e9c77f4-1630519809

All cookies value are different, just posted for your understand. Check key params.

Missing:

.fiverr.com
TRUE	/	FALSE
#HttpOnly_www.fiverr.com
#HttpOnly_.fiverr.com

session_referer
guid_ext