PHP curl changes the Content-Type to application/x-www-form-urlencoded. Shouldn't do that -


i want upload video direct youtube server using php curl.

i need request format:

post /feeds/api/users/default/uploads http/1.1 host: uploads.gdata.youtube.com authorization: bearer access_token gdata-version: 2 x-gdata-key: key=adf15ee97731bca89da876c...a8dc slug: video-test.mp4 content-type: multipart/related; boundary="f93dcba3" content-length: 1941255 connection: close  --f93dcba3 content-type: application/atom+xml; charset=utf-8  <?xml version="1.0"?> <entry xmlns="http://www.w3.org/2005/atom"   xmlns:media="http://search.yahoo.com/mrss/"   xmlns:yt="http://gdata.youtube.com/schemas/2007">   <media:group>     <media:title type="plain">bad wedding toast</media:title>     <media:description type="plain">       gave bad toast @ friend's wedding.     </media:description>     <media:category       scheme="http://gdata.youtube.com/schemas/2007/categories.cat">people     </media:category>     <media:keywords>toast, wedding</media:keywords>   </media:group> </entry> --f93dcba3 content-type: video/mp4 content-transfer-encoding: binary  <binary file data> --f93dcba3-- 

this have:

$content = $this->buildrequestcontent();  $ch = curl_init();  $curlconfig = array(     curlopt_url => 'http://uploads.gdata.youtube.com/feeds/api/users/default/uploads',     curlopt_post => true,     curlopt_returntransfer => true,     curlopt_binarytransfer => true,     curlopt_postfields => $content,     curlopt_httpheader, array(         "authorization" => sprintf("googlelogin auth=%s", $this->accesstoken),         "gdata-version" => 2,         "x-gdata-key" => sprintf("key=%s", $this->developerkey),         "slug" => sprintf("%s", $this->video->getfilename()),         "content-type" => sprintf("multipart/related; boundary=\"%s\"", $this->boundarystring),         "content-length" => strlen($content),         "connection" => "close"     ), );  curl_setopt_array($ch, $curlconfig);  $result = curl_exec($ch); 

dumping result shows me curl changed content-type application/x-www-form-urlencoded of course not supported youtube.

i put binary content (the video) curlopt_postfields, maybe wrong, don't know how set request body other that.

so how preserve content-type set?

according documentation section regarding options' parameter setting http method post defaults content type being set application/x-www-form-urlencoded. suspicion setting options @ once, results in content-type being overwritten.
suggestion set content type in single statement, after you've set method, i.e.

$curlconfig = array(     curlopt_url => 'http://uploads.gdata.youtube.com/feeds/api/users/default/uploads',     curlopt_post => true,     curlopt_returntransfer => true,     curlopt_binarytransfer => true,     curlopt_postfields => $content, );  curl_setopt_array($ch, $curlconfig);  curl_setopt($ch, curlopt_httpheader, array(     'authorization: ' . sprintf('googlelogin auth=%s', $this->accesstoken),     'gdata-version: 2',     'x-gdata-key: ' . sprintf('key=%s', $this->developerkey),     'slug: ' . sprintf('%s', $this->video->getfilename()),     'content-type: ' . sprintf('multipart/related; boundary="%s"',                                   $this->boundarystring),     'content-length: ' . strlen($content),     'connection: close' )); 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -