Closed chongzi5210 closed 6 years ago
@chongzi5210 提供一下你的操作代码
同时,由于前面的(string)
,这里实际执行的是 __toString()
方法
/**
* Return the string representation as a URI reference.
* Depending on which components of the URI are present, the resulting
* string is either a full URI or relative reference according to RFC 3986,
* Section 4.1. The method concatenates the various components of the URI,
* using the appropriate delimiters:
* - If a scheme is present, it MUST be suffixed by ":".
* - If an authority is present, it MUST be prefixed by "//".
* - The path can be concatenated without delimiters. But there are two
* cases where the path has to be adjusted to make the URI reference
* valid as PHP does not allow to throw an exception in __toString():
* - If the path is rootless and an authority is present, the path MUST
* be prefixed by "/".
* - If the path is starting with more than one "/" and no authority is
* present, the starting slashes MUST be reduced to one.
* - If a query is present, it MUST be prefixed by "?".
* - If a fragment is present, it MUST be prefixed by "#".
*
* @see http://tools.ietf.org/html/rfc3986#section-4.1
* @return string
*/
public function __toString()
{
return self::composeComponents(
$this->scheme,
$this->getAuthority(),
$this->path,
$this->query,
$this->fragment
);
}
Swoft\HttpClient\Adapter\CurlAdapter
里面的写法也是一致的
curl_setopt($resource, CURLOPT_URL, (string)$request->getUri()->withFragment(''));
$client = new Client([
'adapter' => 'co',
'base_uri' => 'http://xxx.xxx.xxx.xxx:xxxx',
]);
$response = $client->post({path},[
"json" => [
"test"=>1
]
])->getResponse();
自己写了个php脚本测试可以获取到。但是项目调用一个后台服务,是python的tonado框架写的,报404。 查swoole的手册,发现post 方法有个说明 ,请求的path 不能带 http://domain. 我尝试修改了下,execute发送不带http://domain的path是可以的。 curl客户端确实是可以的,我猜是不是curl 和swoole_client实现不太一致?
另外 curl客户端那个忽略验证ssl证书的参数是不是写反了?
php --ri swoole
)php -v
)Details
使用 Swoft\HttpClient\Adapter\CoroutineAdapter post请求,报404, 同样地址参数curl的客户端可以正常返回, 看了下源码
这个execute 是不是应该改成