0x00 故障

由于GuzzleHttp在iis上使用错误,于是开始替换其为Unirest,没想到发送了一个curl Array to string conversion 错误

0x01 原因

跟踪调用流程,发现是在curl_setopt时设置CURLOPT_POSTFIELDS后抛出的异常。

查看php文档原因是

CURLOPT_POSTFIELDS setting using an array. The array used to set the POST fields must only contain scalar values. Multidimentional arrays or objects lacking a __toString implementation will cause Curl to error.

即CURLOPT_POSTFIELDS不支持多维数组或没有__toString方法的对象。

0x02 解决

阅读GuzzleHttp和Unirest原来是两者POST的时候参数格式不一致

//GuzzleHttp
[
["name" => $key1,
"contents" => $val1],
["name" => $key2,
"contents" => $val2],
//....
]
//Unirest
[
"key1"=>$val1,
"key2"=>$val2,
//...
]

既然如此,写个转换参数格式的函数即可,如下

function convertGuzzleParamToUnirest($param) {
$res = [];
foreach ($param as $item){
if(is_array($item)){
$res[$item['name']] = $item['contents'];
}
} return $res;
}

0x03 扩展

Unirest获取Response直接用$response->body 即可,而且是已经json_decode后的,比GuzzleHttp的简洁许多。

如果要获取原始返回内容,使用$response->raw_body。

curl Array to string conversion 错误的更多相关文章

  1. php YII2空数组插入报错问题处理 Array to string conversion

    问题描述 前端传空数组 [],php接收后处理不当插入数据库时报错Array to string conversion 参数示例 { "id": 0, //ID整型 "t ...

  2. Notice:Array to string conversion的问题

    如果后台或者前端输出这样的提示: Notice: Array to string conversion 原因是:用 echo  来输出数组,当然会报错,数组应该用print , print_r , 或 ...

  3. php报错Array to string conversion 解决方案,动态输出数据库列名称

    php报错Array to string conversion 解决方案,动态输出数据库列名称 问题:在Windows php5.3环境下使用:<?php echo $row->$keys ...

  4. php,二维数组的输出出现了问题,提示:Notice: Array to string conversion

    <?php $arr=array(array("111","222","333"),array("444",&qu ...

  5. PHP 报错--Array to string conversion,请用print_r() 来输出数组

    报错如下: 原因:数组不能用 echo 来输出 解决办法:print_r() 来输出数组 解决办法:var_dump() 来查看数据类型

  6. ATL and MFC String Conversion Macros

    ATL 7.0介绍了一些新的转换类和宏,为现有的宏提供了重要的改进.新的字符串转换类和名称宏的形式是:C 源类型 2[C] 目标类型[EX]其中:•源类型和目标类型描述如下表.• [C]是目标类型必须 ...

  7. 在MySQL向表中插入中文时,出现:incorrect string value 错误

    在MySQL向表中插入中文时,出现:incorrect string value 错误,是由于字符集不支持中文.解决办法是将字符集改为GBK,或UTF-8.      一.修改数据库的默认字符集   ...

  8. MySQL的Incorrect string value错误

    用以下SQL语句向表2中插入数据: insert into 表2 select * from 表1 结果出现Incorrect string value错误: 打开表2一看,里面全是问号: 后来才发现 ...

  9. Specify a culture in string conversion explicitly

    Specify a culture in string conversion explicitly There are different methods of grouping symbols, l ...

随机推荐

  1. struct2 拦截所有没有登录的用户,强行转到登录界面AuthorizationInterceptor

    package com.sise.action; import java.util.Map; import com.opensymphony.xwork2.Action; import com.ope ...

  2. request.getRequestURI() 、request.getRequestURL() 、request.getContextPath()、request.getServletPath()区别

    request.getRequestURI() /jqueryWeb/resources/request.jsprequest.getRequestURL() http://localhost:808 ...

  3. php截取字符去掉最后一个字符

    $str="中国.美国.俄罗斯.德国."$str=substr($str,0,-1); 输出结果为:中国.美国.俄罗斯.德国

  4. MySQL -- Fast Index Creation

    1.fast index creation简介 MySQL5.5之后,对innodb表创建或删除辅助索引的效率提升了很多,即增加了新的功能fast index creation.因为MySQL5.5之 ...

  5. org.hibernate.exception.ConstraintViolationException: could not insert:

    org.hibernate.exception.ConstraintViolationException: could not insert: 报错原由于xxx.hbm.xml文件里的主键类型设置有问 ...

  6. nginx根据http_user_agent防DDOS

    前端squid反向代理到nginx nginx根据http_user_agent防DDOS 首先查看访问日志,找出可疑访问 找到http_user_agent 的特征,然后再作过滤 "Moz ...

  7. asp.net C#取Excel 合并单元格内容

    asp教程.net c#取excel 合并单元格内容读取excel数据,填充dataset// 连接字符串 string xlspath = server.mappath("~/www.11 ...

  8. 基础003_V7-Memory Resources

    一.综述 参考ug473.pdf. 常用Memory 资源: 在IP核中,Block memory(distributed memory为CLB中的资源): 通常选用Native,而不用AXI接口: ...

  9. 支付接口中常用的加密解密以及验签rsa,md5,sha

    一.常用加密类型分类 1.对称加密:采用单钥对信息进行加密和解密,即同一个秘钥既可以对信息进行加密,也可以进行解密.此类型称之为对称加密.特点速度快,常用于对大量数据信息或文件加密时使用.常用例子:D ...

  10. java、oracle对CLOB处理

    oracle CLOB字段转换位VARCHAR 1.实际上处理CLOB字段的时候,直接TO_CHAR,当长度超过4000的时候,会报错,提示列被截取: CLOB转varchar2:select to_ ...