I have this cURL code below which is running on PHP, yet when I did it with WordPress it didn't work. I tried using WP_REMOTE_POST I couldn't do the return transfer function of cURL, what can be a replacement for that or how can I use cURL in my WordPress website. (PS cURL is enabled and work fine for get method but have errors in post method.)

my cURL code

            $ch = curl_init();
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/xml', 'Content-length: '. strlen($xml)) );
            curl_setopt($ch, CURLOPT_POST, true); 
            curl_setopt($ch, CURLOPT_HEADER, false);
            curl_setopt($ch, CURLOPT_URL,$url);  
            curl_setopt($ch, CURLOPT_POSTFIELDS, $input_xml);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
            $data = curl_exec($ch);
            catch (Exception $e) { echo 'Caught exception: ', $e->getMessage(), "\n";

my wp_remote_post

$response = wp_remote_post( 
            'method' => 'POST',
            'timeout' => 45,
            'redirection' => 5,
            'httpversion' => '1.0',
            'headers' => array(
                'Content-Type' => 'application/xml'
            'body' => $input_xml,
            'sslverify' => false
  • You need to give more detail about 'it didn't work' - provide an error message or the result of your error log
    – mozboz
    Jun 13, 2020 at 19:51
  • whenever i use cURL the webservice response gives 500 internal server error, while there was no error from their side.
    – omarhabeh
    Jun 14, 2020 at 12:40
  • ok, so as you have one case where it works and one case where it doesn't a great way to debug this is to see exactly what all the parameters are in the working case and exactly all the parameters in the failing case and change them one by one to see which ones is failing.
    – mozboz
    Jun 14, 2020 at 12:42
  • i tried that but it seems that WordPress doesn't allow cURL post so i used wp_remote_post and still searching how can i make it redirect from the response, yet there is not a lot of answers about the parameters it takes.
    – omarhabeh
    Jun 15, 2020 at 10:45


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.