gpt4 book ai didi

php - Httpful 帖子和 URL 参数

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:23:16 26 4
gpt4 key购买 nike

我正在使用来自 http://phphttpclient.com/ 的 Httpful PHP 库,这是我的示例代码:

$uri = "https://ideabiz.lk/apicall/token?grant_type=password&username=user&password=pwd&scope=PRODUCTION";

$response= \Httpful\Request::post($uri)
->sendsJson()
->addHeaders(array(
'Accept' => 'application/x-www-form-urlencoded',
'Authorization' => 'Basic b28yWTJqNjJoSDN4dHdHNXVkZHhhd2RjWEhrYTp0Zlp5UU1NVEJTcGZiSGFDWFJmQTFvWTJCb2dh',
))
->send();

echo $response;

但是它没有返回任何东西。 ( body 在这里应该是空的。)我什至尝试过这样

$url = "https://ideabiz.lk/apicall/token";

$response = \Httpful\Request::post($url)
->sendsJson()
->authenticateWith('user', 'pwd')
->body('{
"grant_type":"password",
"scope":"PRODUCTION"
}')
->addHeaders(array(
'Accept' => 'application/x-www-form-urlencoded',
'Authorization' => 'Basic b28yWTJqNjJoSDN4dHdHNXVkZHhhd2RjWEhrYTp0Zlp5UU1NVEJTcGZiSGFDWFJmQTFvWTJCb2dh',
))
->send();

echo $response;

但是,它什么也没有返回。我该怎么办..?

最佳答案

终于这样了

$url = "https://ideabiz.lk/apicall/token?grant_type=password&username=tcmolserviceapp&password=Srilanka201804&scope=PRODUCTION";
$response = \Httpful\Request::post($url)
->expectsJSON()
->body('')
->addHeaders(array(
'Content-Type' => 'application/x-www-form-urlencoded',
'Authorization' => 'Basic b28yWTJqNjJoSDN4dHdHNXVkZHhhd2RjWEhrYTp0Zlp5UU1NVEJTcGZiSGFDWFJmQTFvWTJCb2dh'
))
->send();

$access_token = $response->body->access_token;

使用 ->expectsJSON() 而不是 ->sendsJson()

关于php - Httpful 帖子和 URL 参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50126995/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com