cURL works from Terminal, but not from PHP

后端 未结 4 2007
深忆病人
深忆病人 2021-02-19 00:56

I\'m running into a rather strange issue.

I\'m trying to log into a remote moodle install using curl from PHP.

I have a curl command, which works perfectly in th

4条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-19 01:57

    Most likely your problem is related to HTTP header Expect: 100-continue that cURL sends by default for each POST request.

    The Expect: 100-continue header is used in POST requests containing big data when client is not sure that server will accept such request. In this case client first sends request with only headers including Expect: 100-continue and, if the server's response is successful, send the same request with body (POST data).

    The problem is that not all web servers handle this header correctly. In such cases sending this header is undesired.

    The solution is manually remove Expect header from sending headers by passing array('Expect:') to CURLOPT_HTTPHEADER option. In your case you can simply add 'Expect:' string to $headers array:

    $headers[] = 'Expect:';
    

提交回复
热议问题