This line of code fixed this for me:
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Expect:']);
Obviously, you need to add an empty Expect: header to all the other headers you submit, but this header is what cURL fixes for use with Google HTTP load downloaders.
More details
The Google Docs HTTP (S) load balancing setup has a note at the bottom bottom in Notes and Limitations , which states that HTTP/1.1 100 Continue responses are not supported.
Apparently, by default, cURL will always set Expect: 100-continue headers when sending a POST request. So, apparently, cURL cannot send POST through the default GCE HTTP load balancer.
On the end user side, you see only 502 responses coming back from Google, which is even more confusing, since the same POST on a server that is not behind the load balancer works fine.
However, the presence of Expect: 100-continue causes the Google load balancer to invoke and abort the request.
On the server side, POST data cannot be analyzed (it does not even arrive on the server, although the Content-Length message is correctly reported). In my case, this led to the server returning 500 Internal Server Error, which GCE LB munges sends back to the user as a 502 Bad Gateway error.
After adding an empty Expect: header Expect: my POST data correctly injects it into my load-balanced virtual machines, they parse and return valid responses, and my client receives 200 instead of 502.
Thanks to this issue that helped shed light on this issue.
Ross perkins
source share