public function setBody($stringOrStream)
    {
        if ($stringOrStream instanceof RequestBody) {
            $this->body = $stringOrStream;
            $this->removeHeader("content-length");
            return;
        }

        if ($stringOrStream instanceof InputStream) {
            $this->body = new RequestBody($stringOrStream);
            $this->removeHeader("content-length");
            return;
        }

        try {
            // Use method with string type declaration, so we don't need to implement our own check.
            $this->setBodyFromString($stringOrStream ?? "");
        } catch (\TypeError $e) {
            // Provide a better error message in case of a failure.
            throw new \TypeError(\sprintf(
                "The request body must a string, null, or an instance of %s",
                InputStream::class
            ));
        }
    }
public function setBody($stringOrStream)
    {
        if ($stringOrStream instanceof RequestBody) {
            $this->body = $stringOrStream;
            $this->removeHeader("content-length");
            return;
        }

        if ($stringOrStream instanceof InputStream) {
            $this->body = new RequestBody($stringOrStream);
            $this->removeHeader("content-length");
            return;
        }

        try {
            // Use method with string type declaration, so we don't need to implement our own check.
            $this->setBodyFromString($stringOrStream ?? "");
        } catch (\TypeError $e) {
            // Provide a better error message in case of a failure.
            throw new \TypeError(\sprintf(
                "The request body must a string, null, or an instance of %s",
                InputStream::class
            ));
        }
    }
public function setBody ( $ stringOrStream ) { if ( $ stringOrStream instanceof RequestBody ) { $ this -> body = $ stringOrStream ; $ this -> removeHeader ( "content-length" ) ; return ; } if ( $ stringOrStream instanceof InputStream ) { $ this -> body = new RequestBody ( $ stringOrStream ) ; $ this -> removeHeader ( "content-length" ) ; return ; } try { // Use method with string type declaration, so we don't need to implement our own check. $ this -> setBodyFromString ( $ stringOrStream ?? "" ) ; } catch ( \ TypeError $ e ) { // Provide a better error message in case of a failure. throw new \ TypeError ( \ sprintf ( "The request body must a string, null, or an instance of %s" , InputStream :: class ) ) ; } }
Sets the stream for the message body. Note that using a string will automatically set the Content-Length header
to the length of the given string. Using an InputStream or Body instance will remove the Content-Length header.

@param RequestBody|InputStream|string|null $stringOrStream

@throws \Error
@throws \TypeError
Sets the stream for the message body . Note that using a string will automatically set the Content - Length header to the length of the given string . Using an InputStream or Body instance will remove the Content - Length header .