sendRequest example



    /** * @param array{id: string, name: string, taxRate: float, areaRules?: list<array<string, mixed>>} $tax * * @dataProvider dataProviderTestNetToGross */
    public function testNetToGross(array $tax, float $expectedPrice, float $expectedTax): void
    {
        $this->getContainer()->get('tax.repository')->create([$tax], Context::createDefaultContext());

        $price = $this->sendRequest([
            'price' => 10,
            'taxId' => $tax['id'],
            'calculated' => false,
        ]);

        static::assertEquals(
            new CalculatedPrice(
                $expectedPrice,
                $expectedPrice,
                new CalculatedTaxCollection([
                    new CalculatedTax($expectedTax$tax['taxRate']$expectedPrice),
                ]),

    public static function setUpBeforeClass(): void
    {
        TestHttpServer::start();
    }

    public function testSendRequest()
    {
        $factory = new Psr17Factory();
        $client = new Psr18Client(new NativeHttpClient()$factory$factory);

        $response = $client->sendRequest($factory->createRequest('GET', 'http://localhost:8057'));

        $this->assertSame(200, $response->getStatusCode());
        $this->assertSame('application/json', $response->getHeaderLine('content-type'));

        $body = json_decode((string) $response->getBody(), true);

        $this->assertSame('HTTP/1.1', $body['SERVER_PROTOCOL']);
    }

    public function testPostRequest()
    {
        
class HttplugClientTest extends TestCase
{
    public static function setUpBeforeClass(): void
    {
        TestHttpServer::start();
    }

    public function testSendRequest()
    {
        $client = new HttplugClient(new NativeHttpClient());

        $response = $client->sendRequest($client->createRequest('GET', 'http://localhost:8057'));

        $this->assertSame(200, $response->getStatusCode());
        $this->assertSame('application/json', $response->getHeaderLine('content-type'));

        $body = json_decode((string) $response->getBody(), true);

        $this->assertSame('HTTP/1.1', $body['SERVER_PROTOCOL']);
    }

    public function testSendAsyncRequest()
    {
        
        $curlOptions[CURLOPT_SAFE_UPLOAD] = true;

        $curlOptions = $this->setCURLOptions($curlOptions$this->config);
        $curlOptions = $this->applyMethod($method$curlOptions);
        $curlOptions = $this->applyRequestHeaders($curlOptions);

        // Do we need to delay this request?         if ($this->delay > 0) {
            usleep((int) $this->delay * 1_000_000);
        }

        $output = $this->sendRequest($curlOptions);

        // Set the string we want to break our response from         $breakString = "\r\n\r\n";

        if (strpos($output, 'HTTP/1.1 100 Continue') === 0) {
            $output = substr($outputstrpos($output$breakString) + 4);
        }

        if (strpos($output, 'HTTP/1.1 200 Connection established') === 0) {
            $output = substr($outputstrpos($output$breakString) + 4);
        }

        
/** * send a request and get response at once * * @param string $command command as in sendRequest() * @param array $tokens parameters as in sendRequest() * @param bool $dontParse if true unparsed lines are returned instead of tokens * @return mixed response as in readResponse() * @throws Zend_Mail_Protocol_Exception */
    public function requestAndResponse($command$tokens = array()$dontParse = false)
    {
        $this->sendRequest($command$tokens$tag);
        $response = $this->readResponse($tag$dontParse);

        return $response;
    }

    /** * escape one or more literals i.e. for sendRequest * * @param string|array $string the literal/-s * @return string|array escape literals, literals with newline ar returned * as array('{size}', 'string'); */

    public function request($request$multiline = false)
    {
        $this->sendRequest($request);
        return $this->readResponse($multiline);
    }


    /** * End communication with POP3 server (also closes socket) * * @return null */
    public function logout()
    {
        
Home | Imprint | This part of the site doesn't use cookies.