- FOREACH_HASH_KEYVAL(pos, fields, key, idx, data) {
- CURLcode err;
- if (key) {
- zval *orig = *data;
-
- convert_to_string_ex(data);
- err = curl_formadd(&http_post_data[0], &http_post_data[1],
- CURLFORM_COPYNAME, key,
- CURLFORM_COPYCONTENTS, Z_STRVAL_PP(data),
- CURLFORM_CONTENTSLENGTH, (long) Z_STRLEN_PP(data),
- CURLFORM_END
- );
-
- if (orig != *data) {
- zval_ptr_dtor(data);
+ if (fields) {
+ FOREACH_HASH_KEYVAL(pos, fields, key, idx, data) {
+ if (key) {
+ CURLcode err;
+ zval *orig = *data;
+
+ convert_to_string_ex(data);
+ err = curl_formadd(&http_post_data[0], &http_post_data[1],
+ CURLFORM_COPYNAME, key,
+ CURLFORM_COPYCONTENTS, Z_STRVAL_PP(data),
+ CURLFORM_CONTENTSLENGTH, (long) Z_STRLEN_PP(data),
+ CURLFORM_END
+ );
+
+ if (orig != *data) {
+ zval_ptr_dtor(data);
+ }
+
+ if (CURLE_OK != err) {
+ http_error_ex(HE_WARNING, HTTP_E_ENCODING, "Could not encode post fields: %s", curl_easy_strerror(err));
+ curl_formfree(http_post_data[0]);
+ return NULL;
+ }
+
+ /* reset */
+ key = NULL;