2011-08-04 20 views
2

運行與Zend的一個問題,因爲它拋出一個錯誤。我相信這是由於Zend在URL中的下劃線所致。Zend_XmlRpc_Client會強調在主機

我有一個Python客戶端,做同樣的基本功能,它按預期工作。

想知道如果有一個PHP

錯誤解決方法:

Fatal error: Uncaught exception 'Zend_Uri_Exception' with message 'Invalid URI supplied' in /usr/share/php/libzend-framework-php/Zend/Uri/Http.php:156 
Stack trace: 
#0 /usr/share/php/libzend-framework-php/Zend/Uri.php(143): Zend_Uri_Http->__construct('http', '//local_server_f...') 
#1 /usr/share/php/libzend-framework-php/Zend/Http/Client.php(270): Zend_Uri::factory('http://local_ser...') 
#2 /usr/share/php/libzend-framework-php/Zend/XmlRpc/Client.php(266): Zend_Http_Client->setUri('http://local_ser...') 
#3 /usr/share/php/libzend-framework-php/Zend/XmlRpc/Client.php(361): Zend_XmlRpc_Client->doRequest(Object(Zend_XmlRpc_Request)) 
#4 /usr/share/php/libzend-framework-php/Zend/XmlRpc/Client/ServerProxy.php(93): Zend_XmlRpc_Client->call('system.multical...', Array) 
#5 [internal function]: Zend_XmlRpc_Client_ServerProxy->__call('multicall', Array) 
#6 /path/to/xmlrpc.client.php(21): Zend_XmlRpc_Client_ServerProxy->multicall(Array) 
#7 {main} 
    thrown in /usr/share/php/libzend-framework-php/Zend/Uri/Http.php on line 156 

PHP:

ini_set("include_path", "/usr/share/php/libzend-framework-php"); 
require_once('Zend/XmlRpc/Client.php'); 

$server = new Zend_XmlRpc_Client('http://local_server_foo/xmlrpc.server.php'); 

// Get the HTTP Client used by the XMLRPC client and Increase the HTTP timeout 
$server->getHttpClient()->setConfig(array('timeout'=>30)); 

$client = $server->getProxy(); 

$request = array(
    array(
     'methodName' => 'system.listMethods', 
     'params'  => array() 
    ) 
); 

try { 
    $response = $client->system->multicall($request); 
    echo print_r($response,true); 
} catch (Zend_XmlRpc_Client_HttpException $e) { 
    echo 'HTTP Exception: '."\n"; 
    echo $e->getCode(); 
    echo $e->getMessage(); 
} catch (Zend_XmlRpc_Client_FaultException $e) { 
    echo 'Fault Exception: '."\n"; 
    echo $e->getCode(); 
    echo $e->getMessage(); 
} 

的Python(這工作):

#!/usr/bin/python 

import xmlrpclib 

servAddr = "http://local_server_foo/xmlrpc.server.php" 

client = xmlrpclib.ServerProxy(servAddr) 

print 

methods = client.system.listMethods() 
for m in methods: 
    print m + "\tHelp Documentation: " + client.system.methodHelp(m) 
    print 

回答

1

http://en.wikipedia.org/wiki/Hostname(可鏈接到相關的RFC):

The Internet standards (Request for Comments) for protocols mandate that component hostname labels may contain only the ASCII letters 'a' through 'z' (in a case-insensitive manner), the digits '0' through '9', and the hyphen ('-'). The original specification of hostnames in RFC 952, mandated that labels could not start with a digit or with a hyphen, and must not end with a hyphen. However, a subsequent specification (RFC 1123) permitted hostname labels to start with digits. No other symbols, punctuation characters, or white space are permitted.

While a hostname may not contain other characters, such as the underscore character (_), other DNS names may contain the underscore.[3] Systems such as DomainKeys and service records use the underscore as a means to assure that their special character is not confused with hostnames. For example, _http._sctp.www.example.com specifies a service pointer for an SCTP capable webserver host (www) in the domain example.com.

具有主機名下劃線是無效的,而Zend框架的驗證工作正常。

+0

那裏沒有爭論,爲什麼我還沒有提出問題。我看到的唯一的一點是,驗證具有廣泛的驗證上面,然後在年底,標示爲最終的正則表達式「檢查對本地網絡名稱輸入模式;最後的機會,通過驗證」。如果有任何測試爲此而不是爲本地命名模式添加下劃線? –

+0

根據RFC的規定,本地主機名仍不允許有下劃線。如果業務需求決定他們有一個,那麼寫一個自定義驗證器來接受它們。我的正則表達式grokking技能並不總是最好的,但我認爲'最後機會'驗證器是檢查'test.local'或'mydevdomain'這些有效的主機名,而不是tld的域。 –

+0

非常感謝+1的提升。有沒有辦法在驗證中允許特殊字符?也許是一個覆蓋功能? –

1

我剛剛在版本1.11.9中檢查過沒有人抱怨過;也許我應該最終提交一份錯誤報告。我修改/更新Zend_Validate_Hostname類,以便像下面幾行一樣自己填寫缺失的下劃線。它在isValid()方法,這取決於你的版本在線路621(1.11.2)到655(1.11.9)。

老線:

$regexLocal = '/^(([a-zA-Z0-9\x2d]{1,63}\x2e)*[a-zA-Z0-9\x2d]{1,63}){1,254}$/'; 
$status = @preg_match($regexLocal, $value); 

新線:注意變化x5f

$regexLocal = '/^(([a-zA-Z0-9\x2d\x5f]{1,63}\x2e)*[a-zA-Z0-9\x2d]{1,63}){1,254}$/'; 
$status = @preg_match($regexLocal, $value); 

UDPATE讓我們完善這個:

由於@Just^h指出了他的答案下劃線是不允許的,但仍然被廣泛使用。讓我們指責這是在IBM和後來的Microsoft上使用NetBIOS,但爲什麼在本地主機名稱中使用了「儘管不允許」,儘管不允許。

作爲一名前工程師服務器我在大公司見過很多內部網,他們都慷慨的主機名稱中使用下劃線。 OS/2和Windows管理員不知不覺地在DNS命名方案中使用它們。這就是所有瀏覽器都支持它的原因,所有的Web服務器都支持它。

+0

見我爲什麼在的Zend_Validate_Hostname的行爲是正確的,在這種情況下公佈答案。 –

+0

而不是修改模式表達式有沒有辦法在驗證中允許特殊字符?也許是一個覆蓋功能? –

+0

@Phil寫你自己的驗證器,擴展到Zend_Validate_Hostname。添加一個isValid()方法,該方法首先調用父級,然後根據自己的喜好添加上面的驗證。 –