简体   繁体   English

PHP的肥皂-400错误的请求

[英]php soap - 400 bad request

I tried to use a service to out-print text using Typograph by Lebedev. 我试图使用一种服务,使用Lebedev的Typograph打印文本。 I used code from its example on localhost and it works, but when i try to do the same on a server it fails with 400 code. 我在localhost上使用了其示例中的代码,它可以工作,但是当我尝试在服务器上执行相同操作时,它将失败,并显示400代码。 The server is running on the same local machine with the same apache. 服务器在具有相同apache的相同本地计算机上运行。 I tried to increase settings in http.conf (i tried with very short text): LimitRequestLine 16384 LimitRequestFieldSize 12288 我试图增加http.conf中的设置(我尝试使用非常短的文本):LimitRequestLine 16384 LimitRequestFieldSize 12288

I got the following answer: 我得到以下答案:

""" quest\r\n Date: Mon, 25 Jun 2018 14:50:22 GMT\r\n Server: Apache\r\n Vary: Accept-Encoding\r\n Content-Length: 226\r\n Connection: close\r\n Content-Type: text/html; charset=iso-8859-1\r\n \r\n <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">\n <html><head>\n <title>400 Bad Request</title>\n </head><body>\n <h1>Bad Request</h1>\n <p>Your browser sent a request that this server could not understand.<br />\n """

The code of Class: 类的代码:

class Typograph
{
    var $_entityType = 4;
    var $_useBr = 1;
    var $_useP = 1;
    var $_maxNobr = 3;
    var $_encoding = 'UTF-8';
    var $_quotA = 'laquo raquo';
    var $_quotB = 'bdquo ldquo';

    public function __construct ($encoding = 'utf-8')
    {
        $this->_encoding = $encoding;
    }

    public function htmlEntities()
    {
        $this->_entityType = 1;
    }

    public function xmlEntities()
    {
        $this->_entityType = 2;
    }

    public function mixedEntities()
    {
        $this->_entityType = 4;
    }

    public function noEntities()
    {
        $this->_entityType = 3;
    }

    public function br ($value)
    {
        $this->_useBr = $value ? 1 : 0;
    }

    public function p ($value)
    {
        $this->_useP = $value ? 1 : 0;
    }

    public function nobr ($value)
    {
        $this->_maxNobr = $value ? $value : 0;
    }

    public function quotA ($value)
    {
        $this->_quotA = $value;
    }

    public function quotB ($value)
    {
        $this->_quotB = $value;
    }

    public function processText ($text)
    {
        $text = str_replace ('&', '&amp;', $text);
        $text = str_replace ('<', '&lt;', $text);
        $text = str_replace ('>', '&gt;', $text);

        $SOAPBody = '<?xml version="1.0" encoding="' . $this->_encoding . '"?>
        <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
          <soap:Body>
            <ProcessText xmlns="http://typograf.artlebedev.ru/webservices/">
              <text>' . $text . '</text>
              <entityType>' . $this->_entityType . '</entityType>
              <useBr>' . $this->_useBr . '</useBr>
              <useP>' . $this->_useP . '</useP>
              <maxNobr>' . $this->_maxNobr . '</maxNobr>
              <quotA>' . $this->_quotA . '</quotA>
              <quotB>' . $this->_quotB . '</quotB>
            </ProcessText>
          </soap:Body>
        </soap:Envelope>';

        $host = 'typograf.artlebedev.ru';
        $SOAPRequest = 'POST /webservices/typograf.asmx HTTP/1.1
                        Host: typograf.artlebedev.ru
                        Content-Type: text/xml
                        Content-Length: ' . strlen ($SOAPBody). '
                        SOAPAction: "http://typograf.artlebedev.ru/webservices/ProcessText"
                        '.
            $SOAPBody;

        $remoteTypograf = fsockopen ($host, 80);
        fwrite ($remoteTypograf, $SOAPRequest);
        $typografResponse = '';

        while (!feof ($remoteTypograf))
        {
            $typografResponse .= fread ($remoteTypograf, 8192);
        }
        fclose ($remoteTypograf);


        $startsAt = strpos ($typografResponse, '<ProcessTextResult>') + 19;
        $endsAt = strpos ($typografResponse, '</ProcessTextResult>');
        $typografResponse = substr ($typografResponse, $startsAt, $endsAt - $startsAt - 1);

        $typografResponse = str_replace ('&amp;', '&', $typografResponse);
        $typografResponse = str_replace ('&lt;', '<', $typografResponse);
        $typografResponse = str_replace ('&gt;', '>', $typografResponse);


        return  $typografResponse;
    }
}

My call is simple: 我的电话很简单:

$typograph = new App\services\Typograph();
return $typograph->processText('any text');

I tried GET and POST methods and sent Ajax request too with phpstorm. 我尝试了GET和POST方法,并使用phpstorm发送了Ajax请求。

Could you help me? 你可以帮帮我吗? I could not find something relevant to my problem. 我找不到与我的问题有关的东西。 I don't understand even what is wrong. 我什至不明白什么是错。 Why it works on localhost and don't work on site.dev on the same server. 为什么它可以在localhost上运行,而不能在同一服务器上的site.dev上运行。

The solution is simple: i just needed to remove spaces. 解决方案很简单:我只需要删除空格即可。

$SOAPRequest = 'POST /webservices/typograf.asmx HTTP/1.1' . "\n" .
                    'Host: typograf.artlebedev.ru'  . "\n" .
                    'Content-Type: text/xml'  . "\n" .
                    'Content-Length: ' . strlen ($SOAPBody)  . "\n" .
                    'SOAPAction: "http://typograf.artlebedev.ru/webservices/ProcessText"'  . "\n\n" .
        $SOAPBody;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM