diff --git a/mnet/lib.php b/mnet/lib.php
index <HASH>..<HASH> 100644
--- a/mnet/lib.php
+++ b/mnet/lib.php
@@ -100,6 +100,19 @@ function mnet_get_public_key($uri, $application=null) {
     }
 
     $res = xmlrpc_decode(curl_exec($ch));
+
+    // check for curl errors
+    $curlerrno = curl_errno($ch);
+    if ($curlerrno!=0) {
+        debugging("Request for $uri failed with curl error $curlerrno");
+    } 
+
+    // check HTTP error code
+    $info =  curl_getinfo($ch);
+    if (!empty($info['http_code']) and ($info['http_code'] != 200)) {
+        debugging("Request for $uri failed with HTTP code ".$info['http_code']);
+    }
+
     curl_close($ch);
 
     if (!is_array($res)) { // ! error
@@ -115,8 +128,17 @@ function mnet_get_public_key($uri, $application=null) {
                 mnet_set_public_key($uri, $public_certificate);
                 return $public_certificate;
             }
+            else {
+                debugging("Request for $uri returned public key for different URI - $host");
+            }
+        }
+        else {
+            debugging("Request for $uri returned empty response");
         }
     }
+    else {
+        debugging( "Request for $uri returned unexpected result");
+    }
     return false;
 }
MDL-<I>
Added some debugging messages, if anything fails.

Merged from STABLE_<I>