You are here

HTTP错误

老葛的Drupal培训班 Think in Drupal

前面的代码也适用与HTTP错误,比如当服务器不存在,但是该路径上的web服务不存在时.现在,我们向drupal.org请求该服务, drupal.org指出 http://drupal.org/RPC2不存在:

 
$state = xmlrpc('http://drupal.org/RPC2', 'examples.getStateName');
if ($error = xmlrpc_error()) {
if ($error->code <= 0) {
$error->message = t('Outgoing HTTP request failed because the socket could
not be opened.');
}
drupal_set_message(t('Could not get state name because the remote site gave
an error: %message (@code).', array(
'%message' => $error->message,
'@code' => $error->code
)
)
);
 
这将生成如下所示的消息:
 
无法获取州名,因为远程网站给出了一个错误: 未找到 (404).
 

Drupal版本: