示例#1
0
    /**
     * GET Request
     *
     * @param $url
     * @param $datas
     * @return string
     */
    public function get_request($url, $datas = array())
    {
        $body = '';
        try {
            $url2 = new Net_URL2($url);
            foreach ($datas as $key => $val) {
                $url2->setQueryVariable($key, mb_convert_encoding($val, $this->response_encoding, 'UTF-8'), true);
            }

            $this->http->setURL($url2);
            $this->http->setMethod(HTTP_Request2::METHOD_GET);
            if (!empty($this->cookies)) {
                foreach ($this->cookies as $cookie) {
                    $this->http->addCookie($cookie['name'], $cookie['value']);
                }
            }

            $response = $this->http->send();

            if (count($response->getCookies())) {
                $this->cookies = $response->getCookies();
            }

            $body = mb_convert_encoding($response->getBody(), 'UTF-8', $this->response_encoding);

        } catch (Exception $e) {
            debug($e->getMessage());
        }

        return $body;
    }
示例#2
0
 function retrive()
 {
     $req = new HTTP_Request2("");
     $req->setURL($this->api_url);
     $res = $req->send();
     $resbody = $res->getBody();
     if ($resbody) {
         $xml = $resbody;
     } else {
         return 0;
     }
     if ($xml) {
         $fp = fopen($this->file_path, "w");
         fputs($fp, $xml);
         fclose($fp);
         return 1;
     } else {
         return 0;
     }
 }
示例#3
0
function readFolder($folder)
{
    global $vfs, $basepath, $dbh, $update, $host;
    static $level;
    $level++;
    if (substr($folder, -5) == '/.svn') {
        return;
    }
    checkDocLog('readFolder ' . $folder);
    $result = $vfs->listFolder($folder);
    if ($folder == '.') {
        $folder = '';
    }
    foreach ($result as $file) {
        if (is_dir($basepath . $folder . '/' . $file['name'])) {
            if ($folder == '') {
                $newfolder = $file['name'];
            } else {
                $newfolder = $folder . '/' . $file['name'];
            }
            readFolder($newfolder);
            $level--;
        } else {
            if ($level == 2 && preg_match("/\\.xml\$/", $file['name'])) {
                $path = $basepath . $folder . '/' . $file['name'];
                try {
                    list($title, $package) = checkDocumentation($path);
                    $url = '/manual/en/' . $package . '.php';
                    checkDocLog('trying  ' . $host . $url);
                    $request = new HTTP_Request2($host . $url);
                    $response = $request->send();
                    if ($response->getStatus() >= 400) {
                        $new_url = preg_replace("=\\.([^\\.]+)\\.php\$=", ".php", $url);
                        $request->setURL($host . $new_url);
                        checkDocLog('trying2 ' . $host . $new_url);
                        $response = $request->send();
                        $url = $response->getStatus() > 400 ? '' : $new_url;
                    }
                    if ($url) {
                        checkDocLog('Found doc url: ' . $url . ', title: ' . $title);
                        $res = $dbh->execute($update, array($url, $title));
                    } else {
                        checkDocLog('No url for ' . $title);
                    }
                } catch (Exception $e) {
                    print $e->getMessage() . "\n";
                }
            }
        }
    }
}
示例#4
0
 /**
  * Required to request the root i-name (XRI) XRD which will provide an
  * error message that the i-name does not exist, or else return a valid
  * XRD document containing the i-name's Canonical ID.
  *
  * @param string $url         URI
  * @param string $serviceType Optional service type
  *
  * @return HTTP_Request
  * @todo   Finish this a bit better using the QXRI rules.
  */
 protected function get($url, $serviceType = null)
 {
     $request = new HTTP_Request2($url, HTTP_Request2::METHOD_GET, $this->getHttpRequestOptions());
     $netURL = new Net_URL2($url);
     $request->setHeader('Accept', 'application/xrds+xml');
     if ($serviceType) {
         $netURL->setQueryVariable('_xrd_r', 'application/xrds+xml');
         $netURL->setQueryVariable('_xrd_t', $serviceType);
     } else {
         $netURL->setQueryVariable('_xrd_r', 'application/xrds+xml;sep=false');
     }
     $request->setURL($netURL->getURL());
     try {
         return $request->send();
     } catch (HTTP_Request2_Exception $e) {
         throw new Services_Yadis_Exception('Invalid response to Yadis protocol received: ' . $e->getMessage(), $e->getCode());
     }
 }
 /**
  * 
  * @param type $method
  * @param string $url
  * @return \HTTP_Request2
  */
 protected function createClient($method = 'GET', $urlPart = null)
 {
     $url = $this->url . $this->requestPath;
     if ($urlPart) {
         $url .= '/' . $urlPart;
     }
     $request = new HTTP_Request2();
     $request->setMethod($method);
     $request->setURL($url);
     $request->setConfig(array('ssl_verify_peer' => false));
     return $request;
 }
示例#6
0
文件: edit.php 项目: stof/pearweb
$project_link->addFilter("htmlspecialchars");
$project_link->addRule('required', "Please enter your project link");
$is_active = $form->addElement("checkbox", 'is_active', array('checked' => $channel["is_active"] ? 'checked' : ''));
$is_active->setLabel("Active?");
$form->addElement("submit");
if ($form->validate()) {
    $url = new Net_URL2($project_name->getValue());
    try {
        $req = new HTTP_Request2();
        $dir = explode("/", $url->getPath());
        if (!empty($dir)) {
            array_pop($dir);
        }
        $dir[] = 'channel.xml';
        $url->setPath(implode("/", $dir));
        $req->setURL($url->getURL());
        channel::validate($req, $chan);
        channel::edit($channel['name'], $project_label->getValue(), $project_link->getValue(), $contact_name->getValue(), $contact_email->getValue());
        if ($is_active->getValue()) {
            channel::activate($channel['name']);
        } else {
            channel::deactivate($channel['name']);
        }
        echo "<div class=\"success\">Changes saved</div>\n";
    } catch (Exception $exception) {
        echo '<div class="errors">';
        switch ($exception->getMessage()) {
            case "Invalid channel site":
            case "Empty channel.xml":
                echo "The submitted URL does not ";
                echo "appear to point to a valid channel site.  You will ";