php - Guzzle 从响应对象中检索 form_params
问题描述
我正在尝试为 GraphQL 调用编写单元测试,但由于“form_params”字段与 GuzzleHttp\Psr7\Stream 对象内容不匹配而失败。我正在查看使用 REST api 调用的现有单元测试,并尝试使用 Guzzle 打印出其“form_params”的内容。在文档中找不到任何内容
$url = \GuzzleHttp\uri_template($url[0], $url[1]);
$options = [
'form_params' => [
'enrollment[user_id]' => 'sis_user_id:' . $userId,
'enrollment[type]' => $enrollmentType,
'enrollment[enrollment_state]' => $enrollmentState,
'enrollment[role_id]' => $role_id
]
];
//the response
$response = $this->client->post($url, $options);
var_dump($response->getBody()->getContents()); // trying to get form_params
转储行给了我这个类似于 form_params 但不完全
"{"sis_section_id":"Section-S15-99190","type":"TeacherEnrollment","role":null,"user":{"id":1,"sis_user_id":234,"login_id":"thackerj","name":"Jeremy Thacker"},"grades":{"unposted_current_grade":null,"unposted_final_grade":null}}"
解决方案
$client = new Client([
'headers' => [
'Accept' => 'application/json',
'Content-Type' => 'application/x-www-form-urlencoded'
]
]);
推荐阅读
- azure - 从 WebApp Sandbox 访问在 Azure 上部署为 WebJob 的 WCF 服务
- jquery - 隐藏的输入值不使用 Jquery 更新
- javascript - 使用 NodeJS N-API 计算浮点值时出现问题
- javascript - 如果目标元素在视线内或通过在溢出 div 中滚动传递,则执行函数
- sql - 如何在 MS Access 的计数查询中返回零值?
- xml - xsltproc 对 XSL 的解释不同
- r - 将行值填充到某个值的右侧
- java - 来自随机生成数字的 Java 直方图
- javascript - Run javascript after input is complete
- vhdl - Moore fsm VHDL Testbench