내 목표는 서버에 POST 요청을 보내고 적절한 응답을받는 것입니다.PHP에서 요청 데이터없이 cURL POST를 보내는 방법은 무엇입니까?
참고 : 각괄호는 자리 표시자를 나타냅니다.
터미널에서 다음 코드를 사용하면 원하는 응답을 얻을 수 있습니다. 나는 400 잘못된 요청 오류가 발생,이 PHP를 사용
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $uri); //$uri is the same that I use in terminal
curl_setopt($ch, CURLOPT_USERPWD,
sprintf('%s:%s', $user, $pass)); //same as terminal user & pass
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$headers = array(
'Content-Type: application/xml', //expect an xml response
);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$curl_result = curl_exec($ch);
:
curl -u <user>:<pass> -H 'Content-Type: application/xml' -X POST https://<rest of url>
나의 현재 PHP는 다음과 같이 보인다.
용장 정보 :
> POST <same url> HTTP/1.1
Authorization: Basic YWRtaW5Ac3Bhcms0NTEuY29tOnNwYXJrc29tZXRoaW5n
Host: <correct host>
Accept: */*
Content-Type: application/xml
Content-Length: -1
Expect: 100-continue
* HTTP 1.0, assume close after body
< HTTP/1.0 400 Bad request
< Cache-Control: no-cache
< Connection: close
< Content-Type: text/html
왜 내가 PHP를 사용할 때 400 잘못된 요청 오류가 발생하지만 오전하지 내가 명령 줄을 사용하는 경우? PHP를 사용하여 원하는 응답을 얻을 수 있도록이 문제를 어떻게 해결할 수 있습니까?
$ header에 'Expect :'를 추가해도 문제가 해결되지 않습니다. 이 수정 이후 자세한 정보에 'Expect : 100-continue'가 더 이상 나타나지 않습니다. – sparkpham