Created
January 15, 2014 10:38
-
-
Save chrisyue/8434135 to your computer and use it in GitHub Desktop.
使用file_get_content发送POST请求
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function tweet($message, $username, $password) | |
{ | |
$context = stream_context_create(array( | |
'http' => array( | |
'method' => 'POST', | |
'header' => sprintf("Authorization: Basic %s\r\n", base64_encode($username.':'.$password)). | |
"Content-type: application/x-www-form-urlencoded\r\n", | |
'content' => http_build_query(array('status' => $message)), | |
'timeout' => 5, | |
), | |
)); | |
$ret = file_get_contents('http://twitter.com/statuses/update.xml', false, $context); | |
return false !== $ret; | |
} | |
// 其中content 就是 request body, 可以使用json格式如果服务器支持('content' => json_encode(array('status' => $message))),比如elasticsearch |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment