本文整理汇总了PHP中Sabre\HTTP\Request::setBody方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::setBody方法的具体用法?PHP Request::setBody怎么用?PHP Request::setBody使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sabre\HTTP\Request
的用法示例。
在下文中一共展示了Request::setBody方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testDigestAuthInt
public function testDigestAuthInt()
{
$this->auth->setQOP(Digest::QOP_AUTHINT | Digest::QOP_AUTH);
list($nonce, $opaque) = $this->getServerTokens(Digest::QOP_AUTHINT | Digest::QOP_AUTH);
$username = 'admin';
$password = 12345;
$nc = '00003';
$cnonce = uniqid();
$digestHash = md5(md5($username . ':' . self::REALM . ':' . $password) . ':' . $nonce . ':' . $nc . ':' . $cnonce . ':' . 'auth-int:' . md5('POST' . ':' . '/' . ':' . md5('body')));
$this->request->setMethod('POST');
$this->request->setHeader('Authorization', 'Digest username="' . $username . '", realm="' . self::REALM . '", nonce="' . $nonce . '", uri="/", response="' . $digestHash . '", opaque="' . $opaque . '", qop=auth-int,nc=' . $nc . ',cnonce="' . $cnonce . '"');
$this->request->setBody('body');
$this->auth->init();
$this->assertTrue($this->auth->validateA1(md5($username . ':' . self::REALM . ':' . $password)), 'Authentication is deemed invalid through validateA1');
}
示例2: testCorrect
function testCorrect()
{
$xml = '<?xml version="1.0"?>
<d:principal-search-property-set xmlns:d="DAV:"/>';
$serverVars = array('REQUEST_METHOD' => 'REPORT', 'HTTP_DEPTH' => '0', 'REQUEST_URI' => '/principals');
$request = new HTTP\Request($serverVars);
$request->setBody($xml);
$server = $this->getServer();
$server->httpRequest = $request;
$server->exec();
$this->assertEquals('HTTP/1.1 200 OK', $server->httpResponse->status, $server->httpResponse->body);
$this->assertEquals(array('Content-Type' => 'application/xml; charset=utf-8'), $server->httpResponse->headers);
$check = array('/d:principal-search-property-set', '/d:principal-search-property-set/d:principal-search-property' => 2, '/d:principal-search-property-set/d:principal-search-property/d:prop' => 2, '/d:principal-search-property-set/d:principal-search-property/d:prop/d:displayname' => 1, '/d:principal-search-property-set/d:principal-search-property/d:prop/s:email-address' => 1, '/d:principal-search-property-set/d:principal-search-property/d:description' => 2);
$xml = simplexml_load_string($server->httpResponse->body);
$xml->registerXPathNamespace('d', 'DAV:');
$xml->registerXPathNamespace('s', 'http://sabredav.org/ns');
foreach ($check as $v1 => $v2) {
$xpath = is_int($v1) ? $v2 : $v1;
$result = $xml->xpath($xpath);
$count = 1;
if (!is_int($v1)) {
$count = $v2;
}
$this->assertEquals($count, count($result), 'we expected ' . $count . ' appearances of ' . $xpath . ' . We found ' . count($result) . '. Full response body: ' . $server->httpResponse->body);
}
}
示例3: substr
function testIssue205()
{
$request = new HTTP\Request(array('REQUEST_METHOD' => 'REPORT', 'HTTP_CONTENT_TYPE' => 'application/xml', 'REQUEST_URI' => '/calendars/user1/calendar1', 'HTTP_DEPTH' => '1'));
$request->setBody('<?xml version="1.0" encoding="utf-8" ?>
<C:calendar-query xmlns:D="DAV:" xmlns:C="urn:ietf:params:xml:ns:caldav">
<D:prop>
<C:calendar-data>
<C:expand start="20120325T220000Z" end="20120401T215959Z"/>
</C:calendar-data>
<D:getetag/>
</D:prop>
<C:filter>
<C:comp-filter name="VCALENDAR">
<C:comp-filter name="VEVENT">
<C:comp-filter name="VALARM">
<C:time-range start="20120325T220000Z" end="20120401T215959Z"/>
</C:comp-filter>
</C:comp-filter>
</C:comp-filter>
</C:filter>
</C:calendar-query>');
$response = $this->request($request);
$this->assertFalse(strpos($response->body, '<s:exception>Exception</s:exception>'), 'Exception occurred: ' . $response->body);
$this->assertFalse(strpos($response->body, 'Unknown or bad format'), 'DateTime unknown format Exception: ' . $response->body);
// Everts super awesome xml parser.
$body = substr($response->body, $start = strpos($response->body, 'BEGIN:VCALENDAR'), strpos($response->body, 'END:VCALENDAR') - $start + 13);
$body = str_replace(' ', '', $body);
$vObject = VObject\Reader::read($body);
$this->assertEquals(1, count($vObject->VEVENT));
}
示例4: sendPROPFIND
function sendPROPFIND($body)
{
$request = new HTTP\Request('PROPFIND', '/', ['Depth' => '0']);
$request->setBody($body);
$this->server->httpRequest = $request;
$this->server->exec();
}
示例5: testExpand
function testExpand()
{
$request = new HTTP\Request(array('REQUEST_METHOD' => 'REPORT', 'HTTP_CONTENT_TYPE' => 'application/xml', 'REQUEST_URI' => '/calendars/user1/calendar1', 'HTTP_DEPTH' => '1'));
$request->setBody('<?xml version="1.0" encoding="utf-8" ?>
<C:calendar-query xmlns:D="DAV:" xmlns:C="urn:ietf:params:xml:ns:caldav">
<D:prop>
<C:calendar-data>
<C:expand start="20120205T230000Z" end="20120212T225959Z"/>
</C:calendar-data>
<D:getetag/>
</D:prop>
<C:filter>
<C:comp-filter name="VCALENDAR">
<C:comp-filter name="VEVENT">
<C:time-range start="20120205T230000Z" end="20120212T225959Z"/>
</C:comp-filter>
</C:comp-filter>
</C:filter>
</C:calendar-query>');
$response = $this->request($request);
// Everts super awesome xml parser.
$body = substr($response->body, $start = strpos($response->body, 'BEGIN:VCALENDAR'), strpos($response->body, 'END:VCALENDAR') - $start + 13);
$body = str_replace(' ', '', $body);
$vObject = VObject\Reader::read($body);
// We only expect 3 events
$this->assertEquals(3, count($vObject->VEVENT), 'We got 6 events instead of 3. Output: ' . $body);
// TZID should be gone
$this->assertFalse(isset($vObject->VEVENT->DTSTART['TZID']));
}
示例6: testQueryTimerange
function testQueryTimerange()
{
$request = new HTTP\Request('REPORT', '/calendars/user1/calendar1', ['Content-Type' => 'application/xml', 'Depth' => '1']);
$request->setBody('<?xml version="1.0" encoding="utf-8" ?>
<C:calendar-query xmlns:D="DAV:" xmlns:C="urn:ietf:params:xml:ns:caldav">
<D:prop>
<C:calendar-data>
<C:expand start="20120226T230000Z" end="20120228T225959Z"/>
</C:calendar-data>
<D:getetag/>
</D:prop>
<C:filter>
<C:comp-filter name="VCALENDAR">
<C:comp-filter name="VEVENT">
<C:time-range start="20120226T230000Z" end="20120228T225959Z"/>
</C:comp-filter>
</C:comp-filter>
</C:filter>
</C:calendar-query>');
$response = $this->request($request);
if (strpos($response->body, 'BEGIN:VCALENDAR') === false) {
$this->fail('Got no events instead of 1. Output: ' . $response->body);
}
// Everts super awesome xml parser.
$body = substr($response->body, $start = strpos($response->body, 'BEGIN:VCALENDAR'), strpos($response->body, 'END:VCALENDAR') - $start + 13);
$body = str_replace(' ', '', $body);
$vObject = VObject\Reader::read($body);
// We expect 1 event
$this->assertEquals(1, count($vObject->VEVENT), 'We got 0 events instead of 1. Output: ' . $body);
}
示例7: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$parameters = json_decode(file_get_contents('parameters.json'));
$url = $parameters->url;
$HostID = $parameters->host;
// Template pour requête HEV
$xsl = new DOMDocument();
$xsl->load('xslt/hev.xsl');
// Configuration du moteur de template
$proc = new XSLTProcessor();
$proc->setParameter('', 'HostID', $HostID);
$proc->importStylesheet($xsl);
// Récupération du résultat
$doc = $proc->transformToDoc(new DOMDocument());
$request = new Request('POST', $url);
$request->setBody($doc->saveXML());
$client = new Client();
$client->addCurlSetting(CURLOPT_SSL_VERIFYPEER, false);
$response = $client->send($request);
$dom = new DOMDocument();
$dom->loadXML($response->getBodyAsString());
//echo "\nVoici la liste des versions compatibles avec ce serveur:\n\n";
$result = array();
foreach ($dom->getElementsByTagName('VersionNumber') as $version) {
$result[] = array($version->getAttribute('ProtocolVersion'), "EBICS version {$version->nodeValue}");
}
$table = new Table($output);
$table->setHeaders(array('Protocole', 'Description'))->setRows($result);
$table->render();
}
示例8: testPrincipalMatchPrincipalProperty
function testPrincipalMatchPrincipalProperty()
{
$xml = <<<XML
<?xml version="1.0"?>
<principal-match xmlns="DAV:">
<principal-property>
<principal-URL />
</principal-property>
<prop>
<resourcetype />
</prop>
</principal-match>
XML;
$request = new Request('REPORT', '/principals', ['Content-Type' => 'application/xml']);
$request->setBody($xml);
$response = $this->request($request, 207);
$expected = <<<XML
<?xml version="1.0"?>
<d:multistatus xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns">
<d:status>HTTP/1.1 200 OK</d:status>
<d:href>/principals/user1/</d:href>
<d:propstat>
<d:prop>
<d:resourcetype><d:principal/></d:resourcetype>
</d:prop>
<d:status>HTTP/1.1 200 OK</d:status>
</d:propstat>
</d:multistatus>
XML;
$this->assertXmlStringEqualsXmlString($expected, $response->getBodyAsString());
}
示例9: testSyncInitialSyncCollection
function testSyncInitialSyncCollection()
{
// Making a change
$this->collection->addChange(['file1.txt'], [], []);
$request = new HTTP\Request('REPORT', '/coll/', ['Content-Type' => 'application/xml']);
$body = <<<BLA
<?xml version="1.0" encoding="utf-8" ?>
<D:sync-collection xmlns:D="DAV:">
<D:sync-token/>
<D:sync-level>1</D:sync-level>
<D:prop>
<D:getcontentlength/>
</D:prop>
</D:sync-collection>
BLA;
$request->setBody($body);
$response = $this->request($request);
$this->assertEquals(207, $response->status, 'Full response body:' . $response->body);
$multiStatus = $this->server->xml->parse($response->getBodyAsString());
// Checking the sync-token
$this->assertEquals('http://sabre.io/ns/sync/1', $multiStatus->getSyncToken());
$responses = $multiStatus->getResponses();
$this->assertEquals(2, count($responses), 'We expected exactly 2 {DAV:}response');
$response = $responses[0];
$this->assertNull($response->getHttpStatus());
$this->assertEquals('/coll/file1.txt', $response->getHref());
$this->assertEquals([200 => ['{DAV:}getcontentlength' => 3]], $response->getResponseProperties());
$response = $responses[1];
$this->assertNull($response->getHttpStatus());
$this->assertEquals('/coll/file2.txt', $response->getHref());
$this->assertEquals([200 => ['{DAV:}getcontentlength' => 3]], $response->getResponseProperties());
}
示例10: sendPROPFIND
public function sendPROPFIND($body)
{
$serverVars = array('REQUEST_URI' => '/', 'REQUEST_METHOD' => 'PROPFIND', 'HTTP_DEPTH' => '0');
$request = new HTTP\Request($serverVars);
$request->setBody($body);
$this->server->httpRequest = $request;
$this->server->exec();
}
示例11: testPatchNoEndRange
public function testPatchNoEndRange()
{
$this->node->put('00000');
$request = new HTTP\Request(array('REQUEST_METHOD' => 'PATCH', 'REQUEST_URI' => '/partial', 'HTTP_X_UPDATE_RANGE' => 'bytes=3-', 'HTTP_CONTENT_TYPE' => 'application/x-sabredav-partialupdate', 'HTTP_CONTENT_LENGTH' => 3));
$request->setBody('111');
$response = $this->request($request);
$this->assertEquals('HTTP/1.1 204 No Content', $response->status, 'Full response body:' . $response->body);
$this->assertEquals('00111', $this->node->get());
}
示例12: testPatchNoEndRange
function testPatchNoEndRange()
{
$this->node->put('00000');
$request = new HTTP\Request('PATCH', '/partial', ['X-Update-Range' => 'bytes=3-', 'Content-Type' => 'application/x-sabredav-partialupdate', 'Content-Length' => '3']);
$request->setBody('111');
$response = $this->request($request);
$this->assertEquals(204, $response->getStatus(), 'Full response body:' . $response->getBodyAsString());
$this->assertEquals('00111', $this->node->get());
}
示例13: testCreateFileJson
function testCreateFileJson()
{
$request = new HTTP\Request('PUT', '/addressbooks/admin/addressbook1/blabla.vcf');
$request->setBody('[ "vcard" , [ [ "UID" , {}, "text", "foo" ] ] ]');
$response = $this->request($request);
$this->assertEquals(201, $response->status, 'Incorrect status returned! Full response body: ' . $response->body);
$foo = $this->cardBackend->getCard('addressbook1', 'blabla.vcf');
$this->assertEquals("BEGIN:VCARD\r\nUID:foo\r\nEND:VCARD\r\n", $foo['carddata']);
}
示例14: testCollectionGet
function testCollectionGet()
{
$serverVars = array('REQUEST_URI' => '/', 'REQUEST_METHOD' => 'GET');
$request = new HTTP\Request($serverVars);
$request->setBody('');
$this->server->httpRequest = $request;
$this->server->exec();
$this->assertEquals(array('Content-Type' => 'application/xml; charset=utf-8', 'DAV' => '1, 3, extended-mkcol', 'Vary' => 'Brief,Prefer'), $this->response->headers);
$this->assertEquals('HTTP/1.1 207 Multi-Status', $this->response->status, 'Incorrect status response received. Full response body: ' . $this->response->body);
}
示例15: testPutUpdate
function testPutUpdate()
{
$request = new HTTP\Request('PUT', '/test.txt');
$request->setBody('Testing updated file');
$this->server->httpRequest = $request;
$this->server->exec();
$this->assertEquals('0', $this->response->getHeader('Content-Length'));
$this->assertEquals(204, $this->response->status);
$this->assertEquals('', $this->response->body);
$this->assertEquals('Testing updated file', file_get_contents($this->tempDir . '/test.txt'));
}