5252 $ request_params = $ _GET ;
5353} elseif ( 'POST ' == $ request_method ) {
5454 $ request_params = $ _POST ;
55+ if ( empty ( $ request_params ) ) {
56+ $ data = file_get_contents ( 'php://input ' );
57+ if ( !empty ( $ data ) ) {
58+ $ request_params = $ data ;
59+ }
60+ }
5561} elseif ( 'PUT ' == $ request_method || 'DELETE ' == $ request_method ) {
5662 $ request_params = file_get_contents ( 'php://input ' );
5763} else {
104110curl_setopt ( $ ch , CURLOPT_HEADER , true ); // enabled response headers
105111// add data for POST, PUT or DELETE requests
106112if ( 'POST ' == $ request_method ) {
113+ $ post_data = is_array ( $ request_params ) ? http_build_query ( $ request_params ) : $ request_params ;
107114 curl_setopt ( $ ch , CURLOPT_POST , true );
108- curl_setopt ( $ ch , CURLOPT_POSTFIELDS , http_build_query ( $ request_params ) );
115+ curl_setopt ( $ ch , CURLOPT_POSTFIELDS , $ post_data );
109116} elseif ( 'PUT ' == $ request_method || 'DELETE ' == $ request_method ) {
110117 curl_setopt ( $ ch , CURLOPT_CUSTOMREQUEST , $ request_method );
111118 curl_setopt ( $ ch , CURLOPT_POSTFIELDS , $ request_params );
@@ -139,4 +146,4 @@ function csajax_debug_message( $message )
139146 if ( true == CSAJAX_DEBUG ) {
140147 print $ message . PHP_EOL ;
141148 }
142- }
149+ }
0 commit comments