1

I get a problem when make GET request (I can say any request).

$link = 'http://URI/PATH/?param1=1&sid=2&sid=3&sid=4' $http = $HttpSocket = new HttpSocket(); $res = $HttpSocket->get($link); if check the request

pr($http);

I see :

[line] => GET /URL/PATH/?param1=1&sid%5B0%5D=2&sid%5B1%5D=3&sid%5B2%5D=4 HTTP/1.1

And I'm getting empty response because server doesn't know parameters like sid%5B0%5D=2

When I try to send parameters as array : $data = array('param1' => '1', 'sid' => array('2','3', '4'));

I see the same changes %5B0%5D - additional indexes.

How to fix it?

Unfortunately , I can not change server side, but if send GET request in Browser, I'll get normal response in JSON format.

gvlasov
  • 18,638
  • 21
  • 74
  • 110
Ruslan
  • 11
  • 1

1 Answers1

0

When you make a get request, you can get the parameters like this:

  • $param1 = $_GET['param1'];
  • $sid= $_GET['sid'];

Tip: use diferente names for the parameters. You have multiples sid. Use sid1, sid2, sid3...

Update: you can get the parameters like this:

$link = 'http://URI/PATH/?param1=1&sid=2&sid=3&sid=4';

$query_str = parse_url($link, PHP_URL_QUERY);
parse_str($query_str, $query_params);
print_r($query_params);

Reference: How to get parameters from a URL string?

Community
  • 1
  • 1
  • Impossible, The server is not my property, I can send requests and get response from it. BTW, it works, if not use cake HttpSocket. – Ruslan Jun 01 '15 at 11:42
  • Found a solution for you! Check this link: http://stackoverflow.com/questions/11480763/how-to-get-parameters-from-this-url-string – renatofranca Jun 01 '15 at 11:52
  • It's not for me. I have not problems to parse requests.The problem is send request array with cake. `$link = 'http://URI/PATH/?param1=1&sid=2&sid=3&sid=4'` – Ruslan Jun 01 '15 at 19:04