- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在使用GuzzleHttp
。我想从 Laravel 向 Nodejs 发送请求。
try {
$client = new \GuzzleHttp\Client();
$url = 'http://localhost:8085/api/test/get';
$headers = [
'Accept' => 'application/json',
];
$res = $client->post($url, [
'headers' => $headers,
'json' => $data,
]);
dd($res->getBody());
}
catch(\Exception $e) {
echo $e->getMessage();
}
我的请求也发送了,但是$res->getBody()
没有显示我的nodejs结果。 (我确信nodejs有响应)
我的nodejs代码:
total_result = _res.length
response.total_result = total_result
response.result = _res
console.log(response)
res.setHeader('Content-Type', 'application/json')
res.status(200).json(response);
dd($res->getBody());
的结果是:
Stream {#2694
-stream: stream resource @1095
wrapper_type: "PHP"
stream_type: "TEMP"
mode: "w+b"
unread_bytes: 0
seekable: true
uri: "php://temp"
options: []
}
-size: null
-seekable: true
-readable: true
-writable: true
-uri: "php://temp"
-customMetadata: []
}
最佳答案
解决了。您应该使用异步请求:
$request = new \GuzzleHttp\Psr7\Request('GET', 'http://httpbin.org');
$promise = $client->sendAsync($request)->then(function ($response) {
echo 'I completed! ' . $response->getBody();
});
$promise->wait();
关于php - GuzzleHttp 不显示来自 Node.js 服务器的响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57751199/
如何使用 GuzzleHttp(版本 6.0)发出 post 请求。我正在尝试执行以下操作并出现错误 我得到图像值 Illuminate\Http\UploadedFile Object (
我有 vagrant 设置。我有一个名为 test-api.local 的域,这是 homestead laravel。当我尝试访问 https://test-api.local/ 时,它运行良好。
这是一个简单的代码片段,但它只是挂起并且没有响应。 $httpClient = new GuzzleHttp\Client(); // version 6.x $headers = [
我应该在我的 Get 请求中发送一些 JSON,服务器在 application/json 中返回一些数据作为响应: $url='http://example.com/var1=123&var2={'
我想在 Laravel 5.8 中使用 Http facade,但我注意到这个版本的 Laravel 中不包含 Http facade,所以我安装了 GuzzleHttp。 但现在我不知道如何用这个包
当我尝试连接到离线或不存在的主机时,出现异常: cURL error 6: Could not resolve host: somedomain.com 那你怎么用这些东西呢? ( https://l
我无法理解如何修改此 cURL进入 Laravel 5.8,得到 {"code":"11", "message":"invalid Request found", "status":"DECLINED
我正在使用 guzzle 查询我的 API。 $client = new Client(); $response = $client->post('xxxxxx',
如何使用 Guzzle 6 创建具有以下条件的 5 个异步请求: 所有请求同时开始 我希望所有请求的超时值为 500 毫秒。如果请求超时,我不希望它中断其他请求 如果请求返回非 200,我不希望它中断
我正在尝试处理请求状态代码,主要是检查状态是否为 200,以防无法处理。我使用一个名为“GuzzleHttp\Client”的包,当出现 404 时,它会给我一个错误: Client error: `
我正在使用 guzzle 查询我的 API。 $client = new Client(); $response = $client->post('xxxxxx',
如何使用 Guzzle 6 创建具有以下条件的 5 个异步请求: 所有请求同时开始 我希望所有请求的超时值为 500 毫秒。如果请求超时,我不希望它中断其他请求 如果请求返回非 200,我不希望它中断
我正在尝试像这个例子一样发出一个帖子请求: $response = $guzzle->post('http://www.website.com/abc.asp?2014:62/9/931/99999'
我同时使用 Guzzle和 Codeigniter 3.0 首次亮相。我也承认我是第一次使用 php 命名空间。 我正在尝试根据文档中提供的示例使用 Guzzle 发出一个非常简单的获取请求。 (Gu
我正在尝试运行 LaunchDarkly,在代码中它说我需要像这样初始化我的类 $client = new LDClient("MY_CLIENT_KEY"); 现在我可以做到了,但是下面发生的错误是
我使用了 GuzzleHttp,我创建了以下命令的请求: use GuzzleHttp\Client; use GuzzleHttp\Psr7\Request; $url = 'http://loca
我正在创建多个以下 GuzzleHttp\Psr7\Requests: use GuzzleHttp\Psr7\Request; $myRequest = new Request( 'GET'
在 Laravel 中,我使用 Leaguewrap 在 handle() 中用这段代码创建了一个命令图书馆: $api = new Api($_ENV['RIOT_KEY']); $staticDa
所以我正在使用 guzzleHttp,我可以获得我想要的响应并捕获错误。 我遇到的唯一问题是,如果基本 URI 错误,整个脚本就会失败...我如何进行某种检查以确保端点确实已启动? $client =
我将 GuzzleHttp 与 API REST 结合使用。我的参数在 $url_complete = 'http://apirest.com/?'.$params; $request = $clie
我是一名优秀的程序员,十分优秀!