THttpClient无法打开流:HTTP请求失败!HTTP/1.1 400个错误请求

2024-06-26 00:24:58 发布

您现在位置:Python中文网/ 问答频道 /正文

这是我用Python编写的连接服务器的代码。在

transport = THttpClient.THttpClient(secureUrl)
protocol = TBinaryProtocol.TBinaryProtocol(transport)
client = EdenRemote.Client(protocol)
transport.open()

print "calling openSession..."
client.openSession(sessionID, 1)

当我像这样用PHP编写上面的代码时

^{pr2}$

然后我得到了以下错误

Array ( [type] => 2 [message] => fopen(https://edenremote.paceap.com/EdenRemote/d11fbf20-ca24-45f0-b176-4a22e28907c5): failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request [file] => /home/abbas/www/local.edenremote.com/sdk/Thrift/Transport/THttpClient.php [line] => 207 )

第207行代码为

public function flush() {
    // God, PHP really has some esoteric ways of doing simple things.
    $host = $this->host_.($this->port_ != 80 ? ':'.$this->port_ : '');

    $headers = array();
    $defaultHeaders = array('Host' => $host,
                            'Accept' => 'application/x-thrift',
                            'User-Agent' => 'PHP/THttpClient',
                            'Content-Type' => 'application/x-thrift',
                            'Content-Length' => TStringFuncFactory::create()->strlen($this->buf_));
    foreach (array_merge($defaultHeaders, $this->headers_) as $key => $value) {
        $headers[] = "$key: $value";
    }

    $options = array('method' => 'POST',
                     'header' => implode("\r\n", $headers),
                     'max_redirects' => 1,
                     'content' => $this->buf_);
    if ($this->timeout_ > 0) {
      $options['timeout'] = $this->timeout_;
    }
    $this->buf_ = '';

    $contextid = stream_context_create(array('http' => $options));
    $this->handle_ = @fopen($this->scheme_.'://'.$host.$this->uri_, 'r', false, $contextid);

    // Connect failed?
    if ($this->handle_ === FALSE) {
      $this->handle_ = null;
      $error = 'THttpClient: Could not connect to '.$host.$this->uri_;
      throw new TTransportException($error, TTransportException::NOT_OPEN);
    }
  }

甚至我也尝试用ssl改变https。我也试过了

$transport = new TFramedTransport($socket, 1024, 1024);

Tags: 代码hosttimeoutthisarrayprotocolheadersoptions
1条回答
网友
1楼 · 发布于 2024-06-26 00:24:58

这是THttpClient调用的问题。第一个参数应该是主机,uri应该在第三个参数中。在

所以确切的说法是

$result = json_decode(exec('./Authenticator.py'));
$liveURL = $result->secureUrl;
$liveURI = preg_replace('#^https?://edenremote.paceap.com#', '', rtrim($result->secureUrl,'/'));
$socket = new THttpClient('edenremote.paceap.com', 80, $liveURI, 'https');
$socket->setTimeoutSecs(50);
$transport = new TBufferedTransport($socket, 1024, 1024);
$protocol = new TBinaryProtocol($transport);
$client = new \edenremotephp\pub\EdenRemote\EdenRemoteClient($protocol);
$transport->open();
$client->openSession($result->sessionID, 1);
$isExist = $client->findUserByEmailAddress($result->sessionID, $account->primaryEmail);
var_dump($isExist);
$client->closeSession($result->sessionID);
echo 'Done';

相关问题 更多 >