body

摘要

body 选项用来控制一个请求(比如:PUT, POST, PATCH)的主体部分。

类型

  • string
  • fopen() resource
  • Psr\Http\Message\StreamInterface

默认值

None

常量

GuzzleHttp\RequestOptions::BODY

可以设置成下述类型:

  • string

    1. // You can send requests that use a string as the message body.
    2. $client->request('PUT', '/put', ['body' => 'foo']);
  • resource returned from fopen()

    1. // You can send requests that use a stream resource as the body.
    2. $resource = fopen('http://httpbin.org', 'r');
    3. $client->request('PUT', '/put', ['body' => $resource]);
  • Psr\Http\Message\StreamInterface

    1. // You can send requests that use a Guzzle stream object as the body
    2. $stream = GuzzleHttp\Psr7\stream_for('contents...');
    3. $client->request('POST', '/post', ['body' => $stream]);