swlib / saber

⚔️ Saber, PHP异步协程HTTP客户端 | PHP Coroutine HTTP client - Swoole Humanization Library
https://packagist.org/packages/swlib/saber
Apache License 2.0
976 stars 124 forks source link

post返回空数组 #120

Open skadiD opened 3 years ago

skadiD commented 3 years ago

使用SaberGM post请求http://api.ttshitu.com/base64得到意外的结果(空内容) 似乎并不是contentType的问题

sy-records commented 3 years ago

提供下复现代码和账户信息~ 可以发我邮箱

skadiD commented 3 years ago

提供下复现代码和账户信息~ 可以发我邮箱 账户信息已私发邮箱 以下为原始代码 $Api = Saber::create([ 'use_pool' => true, 'base_uri' => 'http://api.ttshitu.com', 'headers' => [ 'Content-Type' => ContentType::JSON, ] ]); $ret = $Api->post('/base64', [ 'username' => 'skadi', 'password' => '', 'typeid' => 1001, 'image' => '' ])->body; print_r($ret);

sy-records commented 3 years ago
$ret = $Api->post('/base64', [ 'username' => 'skadi', 'password' => '', 'typeid' => 1001, 'image' => '' ])->body; 
print_r($ret->getContents());

这里是有数据的啊?

{"success":true,"code":"0","message":"success","data":{"result":"9349","id":"Zx3KeRNZQTKEXKbXg_niEQ"}}
skadiD commented 3 years ago

感谢指点,getContents是在文档那里提示了吗?

skadiD commented 3 years ago

@sy-records 发现问题的根源了 似乎是saber在处理body的时候会成为 <ResultMessage><success>true</success><code>0</code><message>success</message><data><result>6939</result><id>c6228a80850e408b967535ec33658b46</id></data></ResultMessage> 使用的是$ret->getContents() 使用getParsedXmlArray()可以解析成功,但是问题是接口返回的明明是json格式的,使用curl是正常返回

sy-records commented 3 years ago

curl代码也给个 抓包对比下

Vany520 commented 1 year ago

我也遇到类似的问题,不知道题主最终解决了没