4
I’m doing some tests with curl_init php
I happen to have the links like this:
http://localhost/produto/novo
Internally it accesses the new.php file, but I’m using htaccess to work with friendly Urls
I need to make a file that will accept queries via curl_init from php that is on another server
If I open the browser and type:
http://localhost/produto/novo?codigo=1
It accepts beauty, that is, the page is operating normally and accepting the parameters.
But if I use this same URL in curl_init it does not accept, it brings me the content of the index.
Now if I put the url with the file name it accepts:
$url = http://localhost/produto/novo.php
curl_init only accesses files directly, not to use friendly url on it?
My request:
...
$dados = array("pedidos" => $pedidos, "status" => $status, "loja" => $loja);
$url = "http://123.123.123.123/recebe.transito.php";
AQUI EU GOSTARIA DE COLOCAR A URL AMIGAVEL
$url = "http://123.123.123.123/recebe.transito"; // SEM O .PHP
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt_array($curl, array(CURLOPT_FOLLOWLOCATION => true));
curl_setopt($curl, CURLOPT_POSTFIELDS, $dados);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$res = curl_exec($curl);
//$res = curl_getinfo($curl, CURLINFO_HTTP_CODE); // Pegar o código de resposta
$result = json_decode($res);
....
My . htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
post your . htaccess
– Marcos Brinner
You need to post your code
htaccess
and the code of your requestcurl
, if not the answers will get too 'speculative''– Wallace Maxters
"Need to make a file that will accept queries via curl_init from php that is on another server". On another server or another file/folder? Are the two servers on your machine running on different ports? Elaborate better so we can help you better.
– Paulo Sakamoto
Just in advance and answering your headline question: yes, Curl works perfectly with friendly url. Curl is an http client like the browser. The problem must be in the implementation.
– Paulo Sakamoto
I put the codes in maybe make it easier to understand
– Marcelo
An interesting thing, the use of URL friendly is not a redirect but rather a "include" of files, that is the index is responsible for displaying the content of other files according to the request, so curl_init should not show the content of index but include, the impression it gives is: either curl_init does not send the full url or php does not understand the url sent by Curl when there is no end file like . php or . html
– Marcelo
Friend, when you say you are displaying the content of index.php, do you mean that it displays the code of index.php, not the result generated by it? If yes, your problem is in setting up your web server. You use apache?
– Paulo Sakamoto
It is not the code no... it is the index page (html)... it is as if he did not understand that there is a request in a file so it shows the contents of the index.
– Marcelo