when CURLOPT_HTTPHEADER need 'Content-Length'

后端 未结 1 1152
囚心锁ツ
囚心锁ツ 2021-01-28 11:54

I have this code in the client side of my application:

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, \"GET\"); 
curl_setopt($ch, CURLOPT_RETURNT         


        
相关标签:
1条回答
  • 2021-01-28 12:29

    If you use http PUT with curl then you have to specify the Content-Length header. Otherwise it is automatically handled by the curl for both GET and POST.

    For example if you are posting the following data with curl with CURLOPT_POSTFIELDS. Then curl will automatically add the length of the data with the header.

    $data = "name=alex&email=none!";
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    

    For better understand, run your curl code using verbose mode and you'll see how its handling the requests and responses.

    curl_setopt($ch, CURLOPT_VERBOSE, true);
    
    0 讨论(0)
提交回复
热议问题