Answer the question
In order to leave comments, you need to log in
Soap - 400 bad request. What could be the problem?
Hello.
I'm trying to connect a typographer from Lebedev to the project, but when sending a request, 400 is returned.
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
"""
$typograph = new \App\Service\Typograph();
$typograph->htmlEntities();
$typograph->br (false);
$typograph->p (true);
$typograph->nobr (3);
$typograph->quotA ('laquo raquo');
$typograph->quotB ('bdquo ldquo');
$res = $typograph->processText('234');
<?php
namespace App\Service;
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 ('&', '&', $text);
$text = str_replace ('<', '<', $text);
$text = str_replace ('>', '>', $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 ('&', '&', $typografResponse);
$typografResponse = str_replace ('<', '<', $typografResponse);
$typografResponse = str_replace ('>', '>', $typografResponse);
return $typografResponse;
}
}
Answer the question
In order to leave comments, you need to log in
The error is in the class itself. There are extra spaces (indents) in the request, they should not be.
You need to do it differently:
$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;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question