I'm trying to send a post request with Python to PHP (I'm using Phalcon PHP).
Python Code:
array_hash =["0x348eb29f3295fedc10b5b869c751fb5479585c7e65169512c3a5ff474bc0e85a", "0x63b2590119f7ea533ed93e6b2e6112410fbf49f99157bc6d7e0ce7469d3d23a8", "0xfbcdc555a3783b5cfa495ad7a5d14a159657a3f0f6b6a68583fb06ebdf984d70"]
json_data = json.dumps({"data_hash": array_hash})
requests.post(php_url, json=json_data)
My Python print array is good, I have this :
{
"data_hash":[
"0x348eb29f3295fedc10b5b869c751fb5479585c7e65169512c3a5ff474bc0e85a",
"0x63b2590119f7ea533ed93e6b2e6112410fbf49f99157bc6d7e0ce7469d3d23a8",
"0xfbcdc555a3783b5cfa495ad7a5d14a159657a3f0f6b6a68583fb06ebdf984d70"
]
}
But now when I'm trying to get it with PHP my array is empty and when I make a loop on the array I have this error :
Invalid argument supplied for foreach()
Here is my PHP code :
if($this->request->isPost()){
error_log($this->request->getPost('data_hash')[0]);
foreach ($this->request->getPost('data_hash') as $value) {
error_log($value);
}
}
But when I send just json string like this :
{"test1": "hello", "test2": "world"}
I can get it in PHP and it works. So... What is wrong with my Python array ?