isteği POST GET isteği çevirmek için php

3 Cevap

i have a hosted script somewhere that only accept POST request. example, some.hosted/script.php

how can i setup another simple php that can accept GET request and then POST it to the hosted script. so that i can put up a link like this: other.site/post2hostedscript.php?postthis=data and then it POST postthis=data to the hosted script.

tnx

edit: post2hostedscript.php do not give any result. the result will go directly to some.hosted/script.php just as if the user POST directly at the hosted script.

3 Cevap

Sizin post2hostedscript.php zorunda kalacak:

  • GET olarak alınan tüm parametreleri getir
  • POST sorgu oluşturmak
  • O Gönder
  • Ve muhtemelen, bu POST isteği sonucu döndürür.


This can probably be done using curl, for instance ; something like this should get you started :

$queryString = $_SERVER['QUERY_STRING'];

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://www.othersite.com/post2hostedscript.php");
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $queryString);
curl_exec($ch);
curl_close($ch);

Curl ile kullanılabilir seçenekleri listesi için, curl_setopt sayfasına bir göz atabilirsiniz.


Here, you'll have to use, at least :

  • CURLOPT_POST: Bir POST isteği, bir GET göndermek istediğiniz gibi
  • CURLOPT_RETURNTRANSFER: Eğer curl_exec isteği sonucu dönmek, ya da isteyip istemediğinize bağlı olarak, o sadece çıktı.
  • CURLOPT_POSTFIELDS: asılacaktır veriler - yani ne gelen isteği sorgu dizesi var.

Gerekirse, sen , and re-send the interesting ones in your own response (see the header function) Onları (see the CURLOPT_HEADER opsiyon) almak gerekecek - Ve POST isteği yanıtı bazı ilginç HTTP başlığını içerebilir unutmayın .

"Kıvırmak" fonksiyonları bir göz atın, onlar size gereken her şeyi sağlar.

Sen hem GET ve POST hem kabul buna neden olacaktır, $ _REQUEST eski komut $ _POST tüm örneklerini yerine düşünebilirsiniz.