如何在Java客户端和PHP服务器之间设置Apache Thrift通信?
我在服务器端有PHP代码:
$header('Content-Type', 'application/x-thrift');
$handler = new MyApplicationHandler();
$processor = new \tutorial\MyApplicationProcessor($handler);
$transport = new TFramedTransport(
new TPhpStream(TPhpStream::MODE_R | TPhpStream::MODE_W));
$protocol = new TBinaryProtocol($transport, true, true);
$transport->open();
$processor->process($protocol, $protocol);
$transport->close();
客户端的Java代码:
THttpClient httpClient =
new THttpClient("http://my.application.com/PhpServer.php");
TTransport transport = new TFramedTransport(httpClient);
transport.open();
TProtocol protocol = new TBinaryProtocol(transport);
MyApplication.Client client = new MyApplication.Client(protocol);
Boolean result = client.someApi(someData); // <-- will crash here
transport.close();
执行此行时客户端将崩溃:
client.someApi(someData);
我的代码中有什么问题吗?