dreamhost-dynamic-dns icon indicating copy to clipboard operation
dreamhost-dynamic-dns copied to clipboard

E_NOTICE caused by missing content type.

Open cburschka opened this issue 8 years ago • 0 comments

The POST request to the Dreamhost API is sent without a content type (application/x-www-form-urlencoded) which PHP will fill in, but also throw an E_NOTICE about.

Unfortunately, if E_NOTICE warnings are enabled, the custom error handler will pick up that (by itself non-fatal) warning and turn it into a fatal error by calling exit().

The best solution seems to be explicitly specifying the content type.

I added it in DreamDynDns\Api\ApiModule::request(), but maybe there's a better place. (Also, adjust for your preferred code-style of course.)

--- a/DreamDynDns/Api/ApiModule.php
+++ b/DreamDynDns/Api/ApiModule.php
@@ -67,8 +67,8 @@ abstract class ApiModule
                     'unique_id' => uniqid($this->uniquePrefix, true)
                 ),
                 $params
-            )
+            ), $this->requestMethod == 'POST' ? ['Content-type' => 'application/x-www-form-urlencoded'] : NULL
         ));
     }

-}
\ No newline at end of file
+}

With this change I got it to successfully set a record.

Thanks! :)

cburschka avatar Apr 07 '16 16:04 cburschka