2017-02-20 171 views
0

我需要在PHP中發送POST請求到this頁面。 以下是值使用curl的PHP中的POST請求不起作用

  1. exam_id = 204(第一學期學位考試2014年11月)
  2. PRN = 140021043673

我無法發送使用捲曲的請求。

$url = 'http://14.139.185.89/cbcsshrCamp/index.php?module=public&page=viewMrks'; 
$myvars = 'exam_id=' . '204 ' . '&prn=' . '140021043673'; 

$ch = curl_init($url); 
curl_setopt($ch, CURLOPT_POST, 1); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $myvars); 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 
curl_setopt($ch, CURLOPT_HEADER, 0); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 

$response = curl_exec($ch); 

這裏是HTPP頭

HTTP/1.1 200 OK Date: Tue, 21 Feb 2017 06:46:40 GMT Server: Apache/2.4.6 (Red Hat) mod_auth_kerb/5.4 PHP/5.4.16 mod_wsgi/3.4 Python/2.7.5 X-Powered-By: PHP/5.4.16 Set-Cookie: PHPSESSID=g7nnmgjj4t9udei7f2epmld2i6; path=/ Expires: Thu, 19 Nov 1981 08:52:00 GMT Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 Pragma: no-cache Vary: Accept-Encoding Transfer-Encoding: chunked Content-Type: text/html; charset=UTF-8 
+1

看看其他POST捲曲的答案和實例,例如[這裏](http://stackoverflow.com/questions/2138527/php-curl-http-post-sample-code?rq=1)。 – lubosdz

+0

感謝您的回覆。但它看起來一樣。 –

+1

請告訴我們確切的問題是什麼。你有錯誤信息嗎?如果是這樣,請編輯您的問題以包含它。 HTTP頭文件的響應也很有用 – 0xJoKe

回答

0

您發送POST請求,你也有捲曲連接參數查詢字符串! 請更改爲GET請求或將參數作爲DATA發送。在捲曲請求 加入這一行:

curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']); 

和變量改爲:

$url = 'http://14.139.185.89/cbcsshrCamp/index.php'; 
$myvars = json_encode([ 
         'module' => 'public', 
         'page' => 'viewMrks', 
         'exam_id' => '204', 
         'prn'  => '140021043673' 
        ]);