2017-06-27 134 views
0

這是我在Python中的代碼連接到服務器,它工作得很好。THttpClient無法打開流:HTTP請求失敗! HTTP/1.1 400錯誤請求

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

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

當我嘗試寫上面的代碼在PHP這樣

$socket = new THttpClient($liveURL, 80, '', '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); 

然後我得到了以下錯誤

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); 
    } 
    } 

即使我試圖用t更改https他ssl。對於運輸,即使我試過

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

回答

1

這是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'; 
相關問題