Example #1
0
 public static function doPost($url, $params = null)
 {
     if (extension_loaded('curl')) {
         return self::_doPostCurl($url, $params);
     }
     $inf = parse_url($url);
     $Request = new StdClass();
     $Request->method = 'POST';
     $Request->host = $inf['host'];
     $Request->port = isset($inf['port']) ? $inf['port'] : 80;
     $Request->path = $inf['path'];
     $Request->headers = array('Host' => $inf['host'], 'Connection' => 'Close', 'Content-Type' => 'application/x-www-form-urlencoded');
     $p = '';
     if (is_array($params) && count($params) > 0) {
         $p = http_build_query($params);
     } else {
         if (is_string($params)) {
             $p = $params;
         }
     }
     if (isset($inf['query']) && strlen($inf['query']) > 0) {
         $p .= ($p ? '&' : '') . $inf['query'];
     }
     $Request->body = $p;
     return HttpUtils::sendRequest($Request);
 }