Converting terminal CURL to PHP CURL? -


how submit test.xml file in php using curl command:

 curl -x post -k -d @test.xml -h "content-type: application/xml" --user username:password https://www.url.com 

this isn't working me:

 $ch = curl_init();   //get response curl  curl_setopt($ch, curlopt_returntransfer, 1);   //set url  curl_setopt($ch, curlopt_url, 'https://username:password@url.com');   //create post array file in  $postdata = array( 'testdata' => '@test.xml',  );  curl_setopt($ch, curlopt_postfields, $postdata);   // execute request  $response = curl_exec($ch); 

i'm wondering how submit xml written in code instead of xml file.

you should not put username , password in url. can use curl_setopt($p, curlopt_userpwd, $username . ":" . $password); $username , $password. eg below:

$p = curl_init($url); curl_setopt($p, curlopt_httpheader, array('content-type: application/xml')); curl_setopt($p, curlopt_header, 1); curl_setopt($p, curlopt_userpwd, $username . ":" . $password); curl_setopt($p, curlopt_postfields, $postdata); curl_setopt($p, curlopt_post, 1); curl_setopt($p, curlopt_returntransfer, true); $return = curl_exec($p); curl_close($p); 

Comments