2017-02-20 92 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' 
        ]);