为了账号安全,请及时绑定邮箱和手机立即绑定

Guzzle http 和 Laravel Http post 方法替换为 get 方法。

Guzzle http 和 Laravel Http post 方法替换为 get 方法。

PHP
慕尼黑5688855 2022-12-11 09:43:07
有关该问题的一些信息:我使用 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。有用!该死。
查看完整描述

1 回答

?
交互式爱情

TA贡献1712条经验 获得超3个赞

问题是......你应该使用 https:// instad of http://



查看完整回答
反对 回复 2022-12-11
  • 1 回答
  • 0 关注
  • 212 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号