簡體   English   中英

使用PHP中的服務器代理的HTTP POST請求

[英]HTTP POST Request using a server proxy in PHP

我正在嘗試執行HTTP發布請求。 我的服務器正在使用代碼運行php腳本

<?
$siteurl = $_REQUEST['address'];
$postdata = '';
$fakeua = 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.0; Trident/5.0)';

$ch = curl_init($siteurl);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_USERAGENT, $fakeua);
curl_setopt($ch, CURLOPT_TIMEOUT, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch);

?>

我在我的JS中這樣稱呼它

$.ajax({
    url: 'http://localhost/server.php',
    type: 'POST',
    data: {
      address: urlToPost
    },
    success: function(response) {
        window.console.log(response);
   }
});

這個對嗎? 應該行嗎? 似乎我從請求中獲得了200 OK,但由於我是正在執行POST請求的網站而沒有顯示它,因此出現了某些錯誤。 我是通過串聯形成url的,只要將它串聯起來就可以了,對嗎? 還是應該傳遞參數?

urlToPost += "&s=" + sessionID + "&a[0]=" + "Girls" + "&t[0]=" + "Laura" + "&i[0]=" + ts2 + "&o[0]=E" + "&r[0]=" + "&l[0]=" + "&b[0]=Album" + "&n[0]=" + "&m[0]=";

通過發布到Google並檢查您是否獲得結果來進行測試。 使用q=參數設置搜索詞。

另外,1秒的超時時間很短。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM