{"id":8078,"date":"2021-07-21T13:29:56","date_gmt":"2021-07-21T18:29:56","guid":{"rendered":"https:\/\/www.rushworth.us\/lisa\/?p=8078"},"modified":"2021-07-21T13:29:56","modified_gmt":"2021-07-21T18:29:56","slug":"php-curl-and-mangled-headers","status":"publish","type":"post","link":"https:\/\/www.rushworth.us\/lisa\/?p=8078","title":{"rendered":"PHP Curl and Mangled Headers"},"content":{"rendered":"<p>I have PHP code that calls out to a SOAP endpoint, gets the response XML, and then does stuff. Well &#8230; that was the plan anyway. What actually happened was nothing. No error set, but the response string was null. Even adding curl debugging produced nothing. Fortunately, the endpoint is a sandbox one and thus available on http without encryption. I was going to do a network trace, so I needed to run the script from my computer. Aaaand STDOUT is where the curl debugging was going, not (as I assumed) STDERR. And look, there actually <em>was <\/em>an error. 400 bad request (how did that not come through to curl_error?!?) &#8212; and it became immediately obvious what my problem was &#8212; the content length is a quoted string instead of an integer.<\/p>\n<p><a href=\"https:\/\/www.rushworth.us\/lisa\/?attachment_id=8081\" rel=\"attachment wp-att-8081\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-8081\" src=\"https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2021\/07\/QuotedContentLengthNoGood.png\" alt=\"\" width=\"986\" height=\"881\" srcset=\"https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2021\/07\/QuotedContentLengthNoGood.png 986w, https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2021\/07\/QuotedContentLengthNoGood-300x268.png 300w, https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2021\/07\/QuotedContentLengthNoGood-768x686.png 768w, https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2021\/07\/QuotedContentLengthNoGood-750x670.png 750w\" sizes=\"auto, (max-width: 986px) 100vw, 986px\" \/><\/a><\/p>\n<p>Sigh! Copy\/paste error where I built out my header. Cleared the escaped quotes from around the strlen call and, voila, my code works perfectly.<\/p>\n<p><a href=\"https:\/\/www.rushworth.us\/lisa\/?attachment_id=8079\" rel=\"attachment wp-att-8079\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-8079\" src=\"https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2021\/07\/QuotedContentLength.png\" alt=\"\" width=\"733\" height=\"301\" srcset=\"https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2021\/07\/QuotedContentLength.png 733w, https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2021\/07\/QuotedContentLength-300x123.png 300w\" sizes=\"auto, (max-width: 733px) 100vw, 733px\" \/><\/a><\/p>\n<p>But a note to my future self &#8212; when PHP&#8217;s curl calls aren&#8217;t producing any output &#8230; try running it from the CLI. Or remember to add the instruction to have verbose output in STDERR!<\/p>\n<pre class=\"lang-php s-code-block\"><code class=\"hljs language-php\">curl_setopt(<span class=\"hljs-variable\">$ch<\/span>, CURLOPT_STDERR, <span class=\"hljs-variable\">$verbose<\/span>);<\/code><\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I have PHP code that calls out to a SOAP endpoint, gets the response XML, and then does stuff. Well &#8230; that was the plan anyway. What actually happened was nothing. No error set, but the response string was null. Even adding curl debugging produced nothing. Fortunately, the endpoint is a sandbox one and thus &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[33],"tags":[1429,1430,35],"class_list":["post-8078","post","type-post","status-publish","format-standard","hentry","category-coding","tag-curl","tag-curlopt","tag-php"],"_links":{"self":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts\/8078","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=8078"}],"version-history":[{"count":2,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts\/8078\/revisions"}],"predecessor-version":[{"id":8083,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts\/8078\/revisions\/8083"}],"wp:attachment":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=8078"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=8078"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=8078"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}