Exemplo n.º 1
0
 private function curl_post($url, $data, $optional = false)
 {
     $c = curl_init();
     curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($c, CURLOPT_URL, $url);
     curl_setopt($c, CURLOPT_POST, 1);
     curl_setopt($c, CURLOPT_POSTFIELDS, $data);
     curl_setopt($c, CURLOPT_HTTPHEADER, array('ssf-use-positional-post-params: true', 'ssf-contents-not-url-encoded: true'));
     $contents = curl_exec($c);
     if ($contents) {
         $info = curl_getinfo($c);
         curl_close($c);
         if (empty($info['http_code'])) {
             return Error::ConnectionFailed("No http code for url {$url} body was {$contents}");
         } else {
             if ($info['http_code'] != 200) {
                 // errors are ok for optional posts, user may have denied permission
                 // however, if it is an optional post and the error is not permission
                 // denied, report an error
                 if (!$optional || $info['http_code'] != 403) {
                     return Error::ConnectionFailed("http_code != 200 for url {$url}. body was {$contents}");
                 } else {
                     return Error::Success();
                 }
             }
         }
         return SSFType::create(array('contents' => $contents));
     }
     curl_setopt($c, CURLINFO_HEADER_OUT, TRUE);
     $contents = curl_getinfo($c);
     $data = print_r($contents, true);
     curl_close($c);
     return Error::ConnectionFailed("Could not open url {$url} info is {$data}");
 }
Exemplo n.º 2
0
 public static function createEmpty()
 {
     $ret = new SSFType();
     $ret->setError(0, 'success');
     return $ret;
 }
Exemplo n.º 3
0
 public static function Success($str = "")
 {
     return SSFType::createWithError(Error::Success, "(Success) {$str}");
 }