REST API新手

ric*_*uck 6 php rest authorization

基本上我已被分配使用第三方REST API在PHP中构建REST请求应用程序.做POST,GET等似乎很简单,但它们有一个称为授权标题的东西,它使用摘要标记.我怎么通过get传递这个?

例如:

$url = "http:/domain/core.xml";
$response = file_get_contents($url);
echo $response;
Run Code Online (Sandbox Code Playgroud)

返回:未找到Digest auth标头

在FireFoxes POSTER中,我只需添加标题"Authorization",其值为"Digest 0:codehere",它就可以了.

Kin*_*nch 9

请参见file_get_contents()

string file_get_contents ( string $filename [, bool $use_include_path = false [, resource $context [, int $offset = -1 [, int $maxlen ]]]] )
Run Code Online (Sandbox Code Playgroud)

第三个参数$context允许您添加由stream_context_create()创建的上下文.请参阅HTTP上下文选项.在那里,您可以找到一个选项header,允许您设置要发送的请求使用的标头,例如Authorization-header


Muh*_*han 5

您可以使用curl进行Rest调用.为了您的帮助,这些是帮助链接: 使用curl的auth令牌

什么是卷曲