2017-02-20 3 views
0

PHP의 this 페이지로 POST 요청을 보내야합니다. 여기 값PHP에서 curl을 사용한 POST 요청이 작동하지 않습니다.

  1. exam_id = 204 (2,014 첫 학기 DEGREE 서류 검토 월)이다
  2. PRN = 140,021,043,673

I 컬을 이용하여 요청을 전송할 수있다. 여기

$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

:

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

및 변수를 변경합니다 컬 요청이 줄을 추가 [여기] (http://stackoverflow.com/questions/2138527/php-curl-http-post-sample-code?rq=1). – lubosdz

+0

답장을 보내 주셔서 감사합니다. 그러나 똑같은 것처럼 보입니다. –

+1

정확한 문제는 무엇입니까? 오류 메시지가 나타 납니까? 그렇다면 질문을 편집하여 포함하십시오. 응답 HTTP 헤더도 유용 할 것입니다. – 0xJoKe

답변

0

당신은 POST 요청을 전송하고 당신은 또한 컬 쿼리 문자열과 같은 매개 변수를 부착하고있다! GET 요청으로 변경하거나 매개 변수를 DATA로 보냅니다. 다른 POST 컬 응답 및 예, 예를 살펴 보자

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