What means data-urlencode in CURL?
curl, php
Solution
The answer is that you don't even need to think about it; consider the following code:
$xmlpost = [
"name" => "PostalAddressConfirmation",
// Lav modtager
"to" => [
"name" => "Jespern",
"address_line1" => "hejvej",
"address_city" => "Odense",
"address_state" => "Syddanmark",
// etc ...
],
// Lav afsender
"from" => [
"name" => "test",
// etc.
],
//Dokument der skal sendes
"object1" => [
"name" => "AddressConfirmation",
"setting_id" => 100,
"file" => "https://www.lob.com/goblue.pdf",
"quantity" => 1,
],
];
$cpt = curl_init("https://api.lob.com/v1/job");
curl_setopt_array($cpt, [
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_USERPWD => 'test_0dc8d51e0acffcb1880e0f19c79b2f5b0cc:',
CURLOPT_POSTFIELDS => http_build_query($xmlpost),
]);
$result = curl_exec($cpt);
The `http_build_query()` function will build the appropriate string to post.
Problem
I have searched many hours trying to figure out what --data-urlencode is in php curl. I tried this, but I dont think its right. ``` $xmlpost .= "object1[file]=@https://www.lob.com/goblue.pdf"; ``` In the documentation it is: ``` --data-urlencode "object1[file]=https://xxx.pdf" \ ``` But what is it in CURL? `curl_setopt($cpt, CURLOPT_??)` Full API DOCS says i need to call this ``` curl https://api.lob.com/v1/jobs \ -u test_0dc8d51e0acffcb1880e0f19c79b2f5b0cc: \ -d "name=Demo Quick Print Job" \ -d "to[name]=Harry Zhang" \ -d "to[address_line1]=123 Test Street" \ -d "to[address_city]=Mountain View" \ -d "to[address_state]=CA" \ -d "to[address_zip]=94085" \ -d "to[address_country]=US" \ -d "from[name]=Leore Avidar" \ -d "from[address_line1]=123 Test Street." \ -d "from[address_line2]=Apt 155" \ -d "from[address_city]=Sunnyvale" \ -d "from[address_state]=CA" \ -d "from[address_zip]=94085" \ -d "from[address_country]=US" \ -d "object1[name]=testobject" \ --data-urlencode "object1[file]=https://www.lob.com/goblue.pdf" \ -d "object1[setting_id]=100" ``` I am therefore trying: ``` <?php $xmlpost = array( "name" => "PostalAddressConfirmation", "to" => array( "name" => "Testing", "address_line1" => "testvej", "address_city" => "test", "address_state" => "test", "address_zip" => "5000", "address_country" => "DK" ), "from" => array( "name" => "test ApS", "address_line1" => "testvej 25", "address_city" => "test", "address_state" => "test", "address_zip" => "5000", "address_country" => "DK" ), "object1" => array( "name" => "test Object", "setting_id" => "100", "file" => "https://lob.com/goblue.pdf" ) ); $cpt = curl_init("https://api.lob.com/v1/job"); curl_setopt_array($cpt, array( CURLOPT_RETURNTRANSFER => 1, CURLOPT_POSTFIELDS => $xmlpost, CURLOPT_USERPWD => 'test_0dc8d51e0acffcb1880e0f19c79b2f5b0cc:', )); $result = curl_exec($cpt); ```