I need to send get a request to the URL test.ru/stop/search/{название} , also to test.ru/route/search/{название1}/{название2}/{название3}

How is this done if there is no name for the parameters?

What I'm trying to do:

  $url = 'http://test.ru/stop/search/Москва' $headers = array ( 'Content-type: application/json', 'Authorization: Bearer ' . $this->access_token, ); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); $x = curl_exec($ch); 

Returns HTTP Error 400. The request URL is invalid.

  • How can you send a GET request for a link which is not ??! will of course issue error 400 or 404. - Arsen
  • @Arsen do you mean test.ru? There's another address - Zhi V
  • No, of course, how can you send a request to the link test.ru/route/search/ subname11/
  • @Arsen, imagine, you can - Gedweb
  • @Gedweb seriously? ) Interesting and what do you get in return? error 400? if you don’t know the link, how can you send the data there? ) this is the same as I say, call me on the phone and tell you only the first two numbers)))) can call? - Arsen

2 answers 2

I think it is worth url through urlencode should get rid

  $url = 'http://test.ru/stop/search/'+urlencode('Москва'); 
  • Brad http%3A%2F%2Ftest.ru%2Fstop%2Fsearch%2F%D0%9C%D0%BE%D1%81%D0%BA%D0%B2%D0%B0 . - Visman
  • @Visman huh that confuses you, the server simply does not understand Russian characters on this and throws 400 (bad request) and so he will understand and decode normally in GET. - Naumov
  • I am confused by the transformation of the colon and slashes. - Visman
  • @Visman yes you are right right there is only Russian characters to encode ... - Naumov

I can advise you to look in the direction of the Apache module mod_rewrite. https://stackoverflow.com/questions/16136521/apache-mod-rewrite-path-name-as-query-parameters

But of course it is better to redirect all incoming requests to the index file and process the CNC in the scripts already.