有关该问题的一些信息:我使用 POST 方法创建 guzzle 客户端,但它替换为 GET 方法。我尝试在 Laravel 7.x 上使用Illuminate\Support\Facades\Http,但得到了同样的错误。API 服务器是 Django Rest Framework。我收到 405 Method Not Allowed 响应。我的代码使用 guzzle: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 但仍然出现相同的错误。然后我使用 LaravelIlluminate\Support\Facades\HttpHttp::withHeaders([ 'Authorization' => ""])->post('http://xapi-staging.uii.ac.id', [ "parameter" => "value",]);请参阅Illuminate\Support\Facades\Http文档: https: //laravel.com/docs/7.x/http-client#request-data使用 Laravel 的结果Illuminate\Support\Facades\Http该方法是 GET 而不是 POST我的路线:我使用 Postman 和 curl。有用!该死。
添加回答
举报
0/150
提交
取消
