【发布时间】:2013-07-16 03:17:29
【问题描述】:
我正在尝试将 JSON 编码数据 HTTP POST 到远程服务器。
使用 cURL,可以这样做
curl -X POST -H "Content-Type: application/json" -d '{"name":"Jeff"}' http://somesite/someuri
我找不到这样做的 Laravel 方法。
[ * * * 更新:我的解决方案 * * * ]
我最终使用了 PHP 的 HttpRequest
$httpRequest_OBJ = new httpRequest($server, HTTP_METH_POST, NULL);
$httpRequest_OBJ->setBody($jsonEncodedData);
$httpRequest_OBJ->setContentType('application/json');
$result = $httpRequest_OBJ->send();
$reply = $result->getBody();
【问题讨论】:
-
每个 PHP 任务都没有“laravel 方法”。只需使用卷曲! php.net/manual/en/curl.examples-basic.php
-
您可以使用
Guzzle来包装您的 curl 请求。 guzzlephp.org -
你可以使用 Httpful bundle,它的语法就像 Laravel 本身一样富有表现力phphttpclient.com