Php Guzzle http和Laravel http post方法替换为get方法。405方法不允许
有关此问题的一些信息:Php Guzzle http和Laravel http post方法替换为get方法。405方法不允许,php,django,laravel,guzzle,guzzlehttp,Php,Django,Laravel,Guzzle,Guzzlehttp,有关此问题的一些信息: 我使用POST方法创建guzzle客户端,但它被替换为GET方法 我尝试在Laravel7.x上使用illumb\Support\Facades\Http,但得到了相同的错误 API服务器是Django Rest框架 我得到了405方法不允许的响应 我使用guzzle的代码: public static function post($url, $headers, $body) { $client = new Client([ 'headers'
- 我使用POST方法创建guzzle客户端,但它被替换为GET方法
- 我尝试在Laravel7.x上使用
,但得到了相同的错误李>illumb\Support\Facades\Http
- API服务器是Django Rest框架李>
- 我得到了405方法不允许的响应
public static function post($url, $headers, $body)
{
$client = new Client([
'headers' => $headers
]);
$response = collect();
try {
$response->code = 200;
$response->body = json_decode($client->post($url, $body)->getBody()->getContents());
} catch (RequestException $e) {
$response->code = $e->getCode();
$response->body = $e->getResponse() ? $e->getResponse()->getBody()->getContents() : $e->getMessage();
$response->url = $url;
}
return $response;
}
public static function posting()
{
$url = 'http://xapi-staging.uii.ac.id';
$headers = [
'Content-Type' => 'application/json',
'Authorization' => ""
];
$body = [
'form_params' => [
"parameter" => "value"
]
];
return static::post($url, $headers, $body);
}
dd(static::posting());
我使用form_params和json,但仍然得到相同的错误
然后我使用Laravelillumb\Support\Facades\Http
Http::withHeaders([
'Authorization' => ""
])->post('http://xapi-staging.uii.ac.id', [
"parameter" => "value",
]);
参见illumb\Support\Facades\Http
doc,网址:
使用LaravelLightlight\Support\Facades\Http的结果
Http::withHeaders([
'Authorization' => ""
])->post('http://xapi-staging.uii.ac.id', [
"parameter" => "value",
]);
方法是GET而不是POST
我的路线:
我用邮递员和卷发。它起作用了!该死
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://xapi-staging.uii.ac.id",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS =>"{\n \"parameter\": \"value"",
CURLOPT_HTTPHEADER => array(
"Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.ey..",
"Content-Type: text/plain"
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
问题是。。。你应该使用https://instad of http://,错误是什么?405方法不允许还有一件事,你能发布你的路由文件吗?更好的说法是路径是硬编码的还是来自路由文件,我会更新它。