Magento 2 – How to Get Parameters from URL in Controller

magento2parameterquerystringurl

http://mystagesite.com/magento232/custom/module/check/?params=<%3Fxml+version%3D"1.0"+encoding%3D"UTF-8"+standalone%3D"yes"%3F>6<%2FRESPONSECODE>Invalid+Session+Token%3A+Session+has+Timed+Out<%2FRESPONSEDESCRIPTION><%2FRESULT>

In above url , api returns some parameters in xml format

I have to get value of params in check contoller but i have got only empty array

using this code $this->getRequest()->getParams()

I already tried above code but it shows empty array

if i remove first three character from parameter %3F than i got result but that parameter returns from api so can't change that one

so if anyone have idea about this than please let me know

Best Answer

Try with below code other option:

$url = 'http://mystagesite.com/magento232/custom/module/check/?params=<%3Fxml+version%3D"1.0"+encoding%3D"UTF-8"+standalone%3D"yes"%3F>6<%2FRESPONSECODE>Invalid+Session+Token%3A+Session+has+Timed+Out<%2FRESPONSEDESCRIPTION><%2FRESULT>';
$url_data = parse_url($url); 

parse_str($url_data['query'], $params); 

echo $params['params'];

hope its work for you