• $postBody = array(
        'attributes' => json_encode( 
            array(
                'name' => FILE_NAME, 
                'parent' => array(
                    'id' => '0'
                )
            ) 
        ), 
        'file' => new CURLFile( realpath(FILE_PATH),'image/png','pic')
    );
    
    ch = curl_init();
    curl_setopt( $ch, CURLOPT_URL, UPLOAD_URI );
    curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
    curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );
    curl_setopt( $ch, CURLOPT_HTTPHEADER, array(
        "Authorization: Bearer ACCESS_TOKEN" ) );
    curl_setopt( $ch, CURLOPT_POST, true );
    curl_setopt( $ch, CURLOPT_POSTFIELDS, $postBody );
    $response = curl_exec( $ch );
    curl_close( $ch );

    How do convert this curl request to wp_remote_post()?

    I have tried like this, but it did not work ( note: curl request is working perfectly )

    wp_remote_post(
        UPLOAD_URI,
        array(
            "body"	   => $postBody,
    	"headers"  => array(
    	    "Authorization" => "Bearer ACCESS_TOKEN",
    	)
        )
    );

    any kind of help will be appeciated.

Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Convert cURL to wp_remote_post’ is closed to new replies.