I was thinking how can I write a function in PHP which will take a single string argument as follows:
function executeHTTP($cmd)
{
//some way to e开发者_StackOverflow社区xecute $cmd
}
Now $cmd is what it contains...
$cmd = "
POST /action/GetUploadToken HTTP/1.1
Host: gdata.youtube.com
Authorization: AuthSub token="DXAA...sdb8"
GData-Version: 2
X-GData-Key: key=adf15ee97731bca89da876c...a8dc
Content-Length: 1941255
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">
I gave a bad toast at my 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>
"
Any idea how can I do that?
http://php.net/manual/pl/function.fsockopen.php
You should look at the cURL extension: http://nl3.php.net/curl
Using fsockopen, as zoldar said, you can make a raw HTTP request.
function executeHTTP($cmd,$host="gdata.youtube.com",$port=80)
{
$fp = fsockopen($host, $port, $errno, $errstr, 30);
if (!$fp) {
echo "$errstr ($errno)<br />\n";
return false;
} else {
fwrite($fp, $cmd);
$data = fread($fp);
fclose($fp);
}
return $data;
}
you'll need to also specify the host and port, but you can set defaults.
Why not use YouTube's PHP SDK?
精彩评论