首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >gcloud函数php post大小问题

问gcloud函数php post大小问题
EN

Stack Overflow用户
提问于 2022-02-07 05:22:22
回答 1查看 125关注 0票数 1

我在PHP中有一个gcloud函数,它接收一个json对象。在我的函数中,我读取json对象如下: file_get_contents('php://input')。

如果我在函数中接收的json对象小于16 it,但当json对象大于16 it时,则返回空。

EN

回答 1

Stack Overflow用户

发布于 2022-02-07 06:28:55

没有代码,客户端也没有服务器端.

您可能会以enctype="multipart/form-data"?https://php.net/manual/en/wrappers.php.php#wrappers.php.input的身份发送

而file_get_contents('php://input')本身是有问题的。

而是使用默认的方法签名,它提供了ServerRequestInterface $request

代码语言:javascript
复制
use GuzzleHttp\Psr7\Response;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
...

public static function on_https( ServerRequestInterface $request ): ResponseInterface {

    $params = $request->getQueryParams();
    $body = $request->getBody();

    $body->rewind(); // or $body->seek(0);
    $bodyText = $body->getContents();
    $data = json_decode($bodyText);

    return (new Response())
        ->withHeader('Content-Type', 'application/json; charset=utf-8')
        ->withBody(Utils::streamFor(json_encode($data)))
        ->withStatus(200);
}

最近,基于文档将一个模板编写器项目推到了GitHub。对于$body->rewind()并不完全确定,这只是流所必需的(它可能已经返回了string )。这需要"guzzlehttp/psr7": "^2.1.0"。另见:什么是PSR-7和如何使用它?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71013872

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档