Skip to content

Commit 903ef73

Browse files
committed
Fix for post requests with unparseable post data (JSON/SOAP)
1 parent 91a37d8 commit 903ef73

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

proxy.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@
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 {
@@ -104,8 +110,9 @@
104110
curl_setopt( $ch, CURLOPT_HEADER, true ); // enabled response headers
105111
// add data for POST, PUT or DELETE requests
106112
if ( '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

Comments
 (0)