<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -103,7 +103,12 @@ class ActiveResource {
 	/**
 	 * The format requests should use to send data (url or xml).
 	 */
-	var $request_format = 'url';
+	var $request_format = 'xml';
+
+	/**
+	 * The curl/url handler
+	 */
+	private $ch;
 
 	/**
 	 * Constructor method.
@@ -204,6 +209,7 @@ class ActiveResource {
 	 * Simple recursive function to build an XML response.
 	 */
 	function _build_xml ($k, $v) {
+		$k = str_replace('_','-',$k);
 		if (is_object ($v) &amp;&amp; strtolower (get_class ($v)) == 'simplexmlelement') {
 			return preg_replace ('/&lt;\?xml(.*?)\?&gt;/', '', $v-&gt;asXML ());
 		}
@@ -252,11 +258,12 @@ class ActiveResource {
 	 * Build the request, call _fetch() and parse the results.
 	 */
 	function _send_and_receive ($url, $method, $data = array ()) {
+
 		$params = '';
 		$el = substr ($this-&gt;element_name, 0, -1);
 		if ($this-&gt;request_format == 'url') {
 			foreach ($data as $k =&gt; $v) {
-				if ($k != 'id' &amp;&amp; $k != 'created-at' &amp;&amp; $k != 'updated-at') {
+				if ($k != 'id' &amp;&amp; $k != 'created_at' &amp;&amp; $k != 'updated_at') {
 					$params .= '&amp;' . $el . '[' . str_replace ('-', '_', $k) . ']=' . rawurlencode ($v);
 				}
 			}
@@ -264,7 +271,7 @@ class ActiveResource {
 		} elseif ($this-&gt;request_format == 'xml') {
 			$params = '&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&lt;' . $el . &quot;&gt;\n&quot;;
 			foreach ($data as $k =&gt; $v) {
-				if ($k != 'id' &amp;&amp; $k != 'created-at' &amp;&amp; $k != 'updated-at') {
+				if ($k != 'id' &amp;&amp; $k != 'created_at' &amp;&amp; $k != 'updated_at') {
 					$params .= $this-&gt;_build_xml ($k, $v);
 				}
 			}
@@ -274,6 +281,8 @@ class ActiveResource {
 		$this-&gt;request_uri = $url;
 		$this-&gt;request_method = $method;
 
+
+
 		$res = $this-&gt;_fetch ($url, $method, $params);
 
 		list ($headers, $res) = explode (&quot;\r\n\r\n&quot;, $res, 2);
@@ -330,53 +339,95 @@ class ActiveResource {
 		return $this;
 	}
 
+	private function _initialize_http($url, $method, $params){
+		if(!extension_loaded('curl')){
+			$this-&gt;ch = fsockopen(parse_url($url,PHP_URL_HOST),parse_url($url,PHP_URL_PORT));
+			if(!$fp) return null;
+		} else {
+			$this-&gt;ch = curl_init ();
+			curl_setopt ($this-&gt;ch, CURLOPT_URL, $url);
+			curl_setopt ($this-&gt;ch, CURLOPT_MAXREDIRS, 3);
+			curl_setopt ($this-&gt;ch, CURLOPT_FOLLOWLOCATION, 0);
+			curl_setopt ($this-&gt;ch, CURLOPT_RETURNTRANSFER, 1);
+			curl_setopt ($this-&gt;ch, CURLOPT_VERBOSE, 0);
+			curl_setopt ($this-&gt;ch, CURLOPT_HEADER, 1);
+			curl_setopt ($this-&gt;ch, CURLOPT_CONNECTTIMEOUT, 10);
+			curl_setopt ($this-&gt;ch, CURLOPT_SSL_VERIFYPEER, 0);
+			curl_setopt ($this-&gt;ch, CURLOPT_SSL_VERIFYHOST, 0);
+		}
+	}
+
+	private function _prepare_http_method_and_params($url,$method,$params){
+		if(!extension_loaded('curl')){
+			fputs($this-&gt;ch, $method . &quot; &quot;.parse_url($url, PHP_URL_PATH).&quot; HTTP/1.1\r\n&quot;);
+			fputs($this-&gt;ch,&quot;Host: &quot;.parse_url($url,PHP_URL_HOST).&quot;\n&quot;);
+			fputs($this-&gt;ch,&quot;Accept: application/xml\r\n&quot;);
+			fputs($this-&gt;ch,&quot;Content-type: application/xml\r\n&quot;);
+			fputs($this-&gt;ch,&quot;Content-length: &quot;.strlen($params).&quot;\r\n\r\n&quot;);
+			fputs($this-&gt;ch,&quot;$params\r\n\r\n&quot;);
+		} else {
+			switch ($method) {
+				case 'POST':
+					curl_setopt ($this-&gt;ch, CURLOPT_POST, 1);
+					curl_setopt ($this-&gt;ch, CURLOPT_POSTFIELDS, $params);
+					break;
+				case 'DELETE':
+					curl_setopt ($this-&gt;ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
+					break;
+				case 'PUT':
+					curl_setopt ($this-&gt;ch, CURLOPT_CUSTOMREQUEST, 'PUT');
+					curl_setopt ($this-&gt;ch, CURLOPT_POSTFIELDS, $params);
+					break;
+				case 'GET':
+				default:
+					break;
+			}
+		}
+	}
+
+	private function _exec_http(){
+		if(!extension_loaded('curl')){
+			$response = &quot;&quot;;
+			while(!feof($this-&gt;ch)) {
+				$response .= fgets($this-&gt;ch, 1024);
+			}
+			return $response;
+		} else {
+			return curl_exec($this-&gt;ch);
+		}
+	}
+
+	private function _close_http(){
+		if(!extension_loaded('curl')){
+			fclose($this-&gt;ch);
+		} else {
+			curl_close($this-&gt;ch);
+		}
+	}
+
 	/**
 	 * Fetch the specified request via cURL.
 	 */
 	function _fetch ($url, $method, $params) {
-		if (! extension_loaded ('curl')) {
-			$this-&gt;error = 'cURL extension not loaded.';
-			return false;
-		}
-		$ch = curl_init ();
-		curl_setopt ($ch, CURLOPT_URL, $url);
-		curl_setopt ($ch, CURLOPT_MAXREDIRS, 3);
-		curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 0);
-		curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
-		curl_setopt ($ch, CURLOPT_VERBOSE, 0);
-		curl_setopt ($ch, CURLOPT_HEADER, 1);
-		curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 10);
-		curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
-		curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
-		if ($this-&gt;request_format == 'xml') {
-			curl_setopt ($ch, CURLOPT_HTTPHEADER, array (&quot;Content-Type: text/xml&quot;, &quot;Length: &quot; . strlen ($params)));
-		}
-		switch ($method) {
-			case 'POST':
-				curl_setopt ($ch, CURLOPT_POST, 1);
-				curl_setopt ($ch, CURLOPT_POSTFIELDS, $params);
-				//curl_setopt ($ch, CURLOPT_HTTPHEADER, array (&quot;Content-Type: application/x-www-form-urlencoded\n&quot;));
-				break;
-			case 'DELETE':
-				curl_setopt ($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
-				break;
-			case 'PUT':
-				curl_setopt ($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
-				curl_setopt ($ch, CURLOPT_POSTFIELDS, $params);
-				//curl_setopt ($ch, CURLOPT_HTTPHEADER, array (&quot;Content-Type: application/x-www-form-urlencoded\n&quot;));
-				break;
-			case 'GET':
-			default:
-				break;
-		}
-		$res = curl_exec ($ch);
+		
+		$this-&gt;_initialize_http($url, $method, $params);
+
+		#if ($this-&gt;request_format == 'xml') {
+		#	curl_setopt ($ch, CURLOPT_HTTPHEADER, array (&quot;Content-Type: text/xml&quot;, &quot;Length: &quot; . strlen ($params)));
+		#}
+
+		$this-&gt;_prepare_http_method_and_params($url,$method,$params);
+
+
+		$res = $this-&gt;_exec_http();
+		
 		if (! $res) {
 			$this-&gt;errno = curl_errno ($ch);
 			$this-&gt;error = curl_error ($ch);
-			curl_close ($ch);
+			$this-&gt;_close_http();
 			return false;
 		}
-		curl_close ($ch);
+		$this-&gt;_close_http();
 		return $res;
 	}
 </diff>
      <filename>ActiveResource.php</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>e1561bbb110f6827adec72005ee83a0aa2f4b5a2</id>
    </parent>
  </parents>
  <author>
    <name>krewenki</name>
    <email>krewenki@gmail.com</email>
  </author>
  <url>http://github.com/krewenki/phpactiveresource/commit/4550079f24a84dae5c43b7f11e329ffd73b1cf42</url>
  <id>4550079f24a84dae5c43b7f11e329ffd73b1cf42</id>
  <committed-date>2009-05-29T08:20:24-07:00</committed-date>
  <authored-date>2009-05-29T08:20:24-07:00</authored-date>
  <message>Added the ability to function without curl, and changed the default format to xml. Ugly and non-dry, will be refactored.</message>
  <tree>94662857ea21d668093eda8730438bb5d50d7fbe</tree>
  <committer>
    <name>krewenki</name>
    <email>krewenki@gmail.com</email>
  </committer>
</commit>
