Esempio n. 1
0
 public function indexAction()
 {
     $client = new HttpClient();
     $client->setAdapter('Zend\\Http\\Client\\Adapter\\Curl');
     $method = $this->params()->fromQuery('method', 'get');
     $client->setUri('http://api-rest/san-restful');
     switch ($method) {
         case 'get':
             $id = $this->params()->fromQuery('id');
             $client->setMethod('GET');
             $client->setParameterGET(array('id' => $id));
             break;
         case 'get-list':
             $client->setMethod('GET');
             break;
         case 'create':
             $client->setMethod('POST');
             $client->setParameterPOST(array('name' => 'samsonasik'));
             break;
         case 'update':
             $data = array('name' => 'ikhsan');
             $adapter = $client->getAdapter();
             $adapter->connect('localhost', 80);
             $uri = $client->getUri() . '?id=1';
             // send with PUT Method, with $data parameter
             $adapter->write('PUT', new \Zend\Uri\Uri($uri), 1.1, array(), http_build_query($data));
             $responsecurl = $adapter->read();
             list($headers, $content) = explode("\r\n\r\n", $responsecurl, 2);
             $response = $this->getResponse();
             $response->getHeaders()->addHeaderLine('content-type', 'text/html; charset=utf-8');
             $response->setContent($content);
             return $response;
         case 'delete':
             $adapter = $client->getAdapter();
             $adapter->connect('localhost', 80);
             $uri = $client->getUri() . '?id=1';
             //send parameter id = 1
             // send with DELETE Method
             $adapter->write('DELETE', new \Zend\Uri\Uri($uri), 1.1, array());
             $responsecurl = $adapter->read();
             list($headers, $content) = explode("\r\n\r\n", $responsecurl, 2);
             $response = $this->getResponse();
             $response->getHeaders()->addHeaderLine('content-type', 'text/html; charset=utf-8');
             $response->setContent($content);
             return $response;
     }
     //if get/get-list/create
     $response = $client->send();
     if (!$response->isSuccess()) {
         // report failure
         $message = $response->getStatusCode() . ': ' . $response->getReasonPhrase();
         $response = $this->getResponse();
         $response->setContent($message);
         return $response;
     }
     $body = $response->getBody();
     $response = $this->getResponse();
     $response->setContent($body);
     return $response;
 }
 /**
  * Sets request handler
  *
  * @param \Zend\Http\Client $handler
  * @return RemoteCompiler
  */
 public function setRequestHandler($handler)
 {
     $this->requestHandler = $handler;
     $this->requestHandler->setUri($this->url)->setMethod($this->method);
     $this->requestHandler->getUri()->setPort($this->port);
     return $this;
 }
Esempio n. 3
0
    public function testIfCookiesAreSticky()
    {
        $initialCookies = array(
            new SetCookie('foo', 'far', null, '/', 'www.domain.com' ),
            new SetCookie('bar', 'biz', null, '/', 'www.domain.com')
        );

        $requestString = "GET http://www.domain.com/index.php HTTP/1.1\r\nHost: domain.com\r\nUser-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:16.0) Gecko/20100101 Firefox/16.0\r\nAccept: */*\r\nAccept-Language: en-US,en;q=0.5\r\nAccept-Encoding: gzip, deflate\r\nConnection: keep-alive\r\n";
        $request = Request::fromString($requestString);

        $client = new Client('http://www.domain.com/');
        $client->setRequest($request);
        $client->addCookie($initialCookies);

        $cookies = new Cookies($client->getRequest()->getHeaders());
        $rawHeaders = "HTTP/1.1 200 OK\r\nAccess-Control-Allow-Origin: *\r\nContent-Encoding: gzip\r\nContent-Type: application/javascript\r\nDate: Sun, 18 Nov 2012 16:16:08 GMT\r\nServer: nginx/1.1.19\r\nSet-Cookie: baz=bah; domain=www.domain.com; path=/\r\nSet-Cookie: joe=test; domain=www.domain.com; path=/\r\nVary: Accept-Encoding\r\nX-Powered-By: PHP/5.3.10-1ubuntu3.4\r\nConnection: keep-alive\r\n";
        $response = Response::fromString($rawHeaders);
        $client->setResponse($response);

        $cookies->addCookiesFromResponse($client->getResponse(), $client->getUri());

        $client->addCookie( $cookies->getMatchingCookies($client->getUri()) );

        $this->assertEquals(4, count($client->getCookies()));
    }
Esempio n. 4
0
 /**
  * Test we can SET and GET a URI as object
  *
  */
 public function testSetGetUriObject()
 {
     $uriobj = new UriHttp('http://www.zend.com:80/');
     $this->_client->setUri($uriobj);
     $uri = $this->_client->getUri();
     $this->assertTrue($uri instanceof UriHttp, 'Returned value is not a Uri object as expected');
     $this->assertEquals($uri, $uriobj, 'Returned object is not the excepted Uri object');
 }
Esempio n. 5
0
 function setPostRut($ruts)
 {
     foreach ($ruts as $rut) {
         $busqueda[] = explode('-', $rut[0]);
     }
     echo '<pre>';
     print_r($busqueda);
     echo '</pre>';
     $client = new Client('http://reca.poderjudicial.cl/', array('maxredirects' => 100, 'timeout' => 600, 'keepalive' => true));
     $headers = $client->getRequest()->getHeaders();
     $cookies = new Zend\Http\Cookies($headers);
     $client->setMethod('GET');
     $response = $client->send();
     $client->setUri('http://reca.poderjudicial.cl/RECAWEB/AtPublicoViewAccion.do?tipoMenuATP=1');
     $cookies->addCookiesFromResponse($response, $client->getUri());
     $response = $client->send();
     $client->setUri("http://reca.poderjudicial.cl/RECAWEB/AtPublicoDAction.do");
     foreach ($busqueda as $rut) {
         $parametros = array('actionViewBusqueda' => '2', 'FLG_Busqueda' => '2', 'FLG_User_Valid' => '0', 'TIP_Lengueta' => 'tdDos', 'COD_Competencia' => 'C', 'tribunal_aux' => '-1', 'username_aux' => '', 'password_aux' => '', 'aux_codlibro' => '', 'aux_rolinterno' => '', 'aux_eracausa' => '', 'aux_codcorte' => '', 'RUT_Cod_Competencia' => 'C', 'RUT_Rut' => $rut[0], 'RUT_Rut_Db' => $rut[1], 'RIT_Cod_Competencia' => '0', 'RIT_Tip_Causa' => '0', 'RIT_Rol_Interno' => '', 'RIT_Era_Causa' => '', 'corte_Cod_Tribunal' => '-1', 'corte_Cod_Libro' => '0', 'corte_Rol_Interno' => '', 'corte_Era_Causa' => '', 'OPC_Cod_Corte' => '-1', 'OPC_Cod_Tribunal' => '-1', 'username' => '', 'password' => '');
         $client->setParameterPost($parametros);
         echo '<pre>';
         print_r($parametros);
         echo '</pre>';
         $response = $client->setMethod('POST')->send();
         $data = $response->getContent();
         echo '<pre>';
         print_r($response->getContent());
         echo '</pre>';
         die;
         $rut = $rut[0] . '-' . $rut[1];
         $dom = new Query($data);
         $resultados = $dom->execute('#divRecursos tr');
         $rols = $this->busquedaRut($resultados, $rut);
     }
 }
 protected function getClientUrl(Client $client)
 {
     $uri = $client->getUri();
     $query = $client->getRequest()->getQuery()->toString();
     //$post = $client->getRequest()->getPost()->toString();
     return $uri . '?' . $query;
 }
Esempio n. 7
0
 /**
  * Make sure we can set an array of object cookies
  *
  */
 public function testSetCookieObjectArray()
 {
     $this->client->setUri($this->baseuri . 'testCookies.php');
     $refuri = $this->client->getUri();
     $cookies = array('chocolate' => 'chips', 'crumble' => 'apple', 'another' => 'cookie');
     $this->client->setCookies($cookies);
     $res = $this->client->send();
     $this->assertEquals($res->getBody(), serialize($cookies), 'Response body does not contain the expected cookies');
 }
Esempio n. 8
0
 public function setZendClient(ZendHttpClient $client)
 {
     $host = $client->getUri()->getHost();
     if (empty($host)) {
         throw new ZendHttpRuntimeException('Host not defined.');
     }
     $this->zendClient = $client;
     return $this;
 }
 public function getCausas($dataPost)
 {
     $cliente = new \Zend\Http\Client('http://civil.poderjudicial.cl', array('maxredirects' => 100, 'timeout' => 600, 'keepalive' => true));
     $headers = $cliente->getRequest()->getHeaders();
     $cookies = new Zend\Http\Cookies($headers);
     $cliente->setMethod('GET');
     $response = $cliente->send();
     $cliente->setUri('http://civil.poderjudicial.cl/CIVILPORWEB/AtPublicoViewAccion.do?tipoMenuATP=1');
     $cookies->addCookiesFromResponse($response, $cliente->getUri());
     $response = $cliente->send();
     $cliente->setUri('http://civil.poderjudicial.cl/CIVILPORWEB/AtPublicoDAction.do');
     $cookies->addCookiesFromResponse($response, $cliente->getUri());
     foreach ($dataPost as $post) {
         $cliente->setParameterPost(array('TIP_Consulta' => '3', 'TIP_Lengueta' => 'tdCuatro', 'SeleccionL' => '0', 'TIP_Causa' => '', 'ROL_Causa' => '', 'ERA_Causa' => '', 'RUC_Era' => '', 'RUC_Tribunal' => '3', 'RUC_Numero' => '', 'RUC_Dv' => '', 'FEC_Desde' => '20/08/2015', 'FEC_Hasta' => '20/08/2015', 'SEL_Litigantes' => '0', 'RUT_Consulta' => '', 'RUT_DvConsulta' => '', 'NOM_Consulta' => $post['Nombre'], 'APE_Paterno' => $post['Apellido_paterno'], 'APE_Materno' => $post['Apellido_materno'], 'COD_Tribunal' => '', 'irAccionAtPublico' => 'Consulta'));
         $response = $cliente->setMethod('POST')->send();
         if ($response->isOk()) {
             $data = $response->getContent();
             echo '<pre>';
             print_r($data);
             echo '</pre>';
         }
     }
 }
Esempio n. 10
0
 /**
  * Proxify an existing client.
  *
  * Returns the client given as argument with appropriate proxy setup.
  *
  * @param \Zend\Http\Client $client  HTTP client
  * @param array             $options ZF2 ProxyAdapter options
  *
  * @return \Zend\Http\Client
  */
 public function proxify(\Zend\Http\Client $client, array $options = array())
 {
     if ($this->proxyConfig) {
         $host = $client->getUri()->getHost();
         if (!$this->isLocal($host)) {
             $adapter = new \Zend\Http\Client\Adapter\Proxy();
             $options = array_replace($this->proxyConfig, $options);
             $adapter->setOptions($options);
             $client->setAdapter($adapter);
         }
     }
     return $client;
 }
Esempio n. 11
0
}
$busqueda = new Scrap();
$busqueda->insertaBusqueda($arreglo);
/*
 * Configuramos el cliente
 */
$client = new Client('http://civil.poderjudicial.cl', array('maxredirects' => 100, 'timeout' => 600, 'keepalive' => true));
/*
 * Obtenemos las cabeceras y seteamos las cookies.
 */
$headers = $client->getRequest()->getHeaders();
$cookies = new Zend\Http\Cookies($headers);
$client->setMethod('GET');
$response = $client->send();
$client->setUri('http://civil.poderjudicial.cl/CIVILPORWEB/AtPublicoViewAccion.do?tipoMenuATP=1');
$cookies->addCookiesFromResponse($response, $client->getUri());
$response = $client->send();
foreach ($arreglo as $demandado) {
    echo "<pre>Se estan buscando las causas para." . $demandado['nombre'] . " " . $demandado['apPaterno'] . " " . $demandado['apMaterno'] . ", RUT: " . $demandado['rut'] . "</pre>";
    $rut = $demandado['rut'];
    echo $rut;
    $client->setUri('http://civil.poderjudicial.cl/CIVILPORWEB/AtPublicoDAction.do');
    $cookies->addCookiesFromResponse($response, $client->getUri());
    $scrap = new Scrap();
    $client->setParameterPost(array('TIP_Consulta' => '3', 'TIP_Lengueta' => 'tdCuatro', 'SeleccionL' => '0', 'TIP_Causa' => '', 'ROL_Causa' => '', 'ERA_Causa' => '', 'RUC_Era' => '', 'RUC_Tribunal' => '3', 'RUC_Numero' => '', 'RUC_Dv' => '', 'FEC_Desde' => '20/08/2015', 'FEC_Hasta' => '20/08/2015', 'SEL_Litigantes' => '0', 'RUT_Consulta' => '', 'RUT_DvConsulta' => '', 'NOM_Consulta' => $demandado['nombre'], 'APE_Paterno' => $demandado['apPaterno'], 'APE_Materno' => $demandado['apMaterno'], 'COD_Tribunal' => '0', 'irAccionAtPublico' => 'Consulta'));
    $response = $client->setMethod('POST')->send();
    if ($response->isSuccess()) {
        $data = $response->getContent();
        $dom = new Query($data);
        $results = $dom->execute('#contentCellsAddTabla tr');
        $informacionCausas = $scrap->getCausas($results);
Esempio n. 12
0
 public function getCausas($dataPost)
 {
     $cliente = new \Zend\Http\Client('http://civil.poderjudicial.cl', array('maxredirects' => 100, 'timeout' => 600, 'keepalive' => true));
     $headers = $cliente->getRequest()->getHeaders();
     $cookies = new Zend\Http\Cookies($headers);
     $cliente->setMethod('GET');
     $response = $cliente->send();
     $cliente->setUri('http://civil.poderjudicial.cl/CIVILPORWEB/AtPublicoViewAccion.do?tipoMenuATP=1');
     $cookies->addCookiesFromResponse($response, $cliente->getUri());
     $response = $cliente->send();
     $cliente->setUri('http://civil.poderjudicial.cl/CIVILPORWEB/AtPublicoDAction.do');
     $cookies->addCookiesFromResponse($response, $cliente->getUri());
     foreach ($dataPost as $post) {
         $arr_rol = explode('-', $post['rol']);
         $rol = $post['rol'];
         $rut = $post['rut'];
         $cliente->setParameterPost(array('TIP_Consulta' => '1', 'TIP_Lengueta' => 'tdUno', 'SeleccionL' => '0', 'TIP_Causa' => $arr_rol[0], 'ROL_Causa' => $arr_rol[1], 'ERA_Causa' => $arr_rol[2], 'RUC_Era' => '', 'RUC_Tribunal' => '3', 'RUC_Numero' => '', 'RUC_Dv' => '', 'FEC_Desde' => '20/08/2015', 'FEC_Hasta' => '20/08/2015', 'SEL_Litigantes' => '0', 'RUT_Consulta' => '', 'RUT_DvConsulta' => '', 'NOM_Consulta' => '', 'APE_Paterno' => '', 'APE_Materno' => '', 'COD_Tribunal' => $post['cod_tribunal'], 'irAccionAtPublico' => 'Consulta'));
         $response = $cliente->setMethod('POST')->send();
         if ($response->isOk()) {
             $data = $response->getContent();
             $causas = $this->CI->funciones->getCausas($data);
             $this->CI->Busqueda_rol->insertCausas($causas, $rut);
             $postCausas = $this->CI->funciones->detalleCausa($causas);
             $cliente->setUri('http://civil.poderjudicial.cl/CIVILPORWEB/ConsultaDetalleAtPublicoAccion.do?');
             $cookies->addCookiesFromResponse($response, $cliente->getUri());
             foreach ($postCausas as $post) {
                 $cliente->setParameterPost(array("TIP_Consulta" => $post['TIP_Consulta'], "TIP_Cuaderno" => $post['TIP_Cuaderno'], "CRR_IdCuaderno" => $post['CRR_IdCuaderno'], "ROL_Causa" => $post['ROL_Causa'], "TIP_Causa" => $post['TIP_Causa'], "ERA_Causa" => $post['ERA_Causa'], "COD_Tribunal" => $post['COD_Tribunal'], "TIP_Informe" => $post['TIP_Informe'] . "&"));
                 $response = $cliente->setMethod('POST')->send();
                 if ($response->isOk()) {
                     $data = $response->getContent();
                     $detalleCausa = $this->CI->funciones->infoCausa($data);
                     $this->CI->Busqueda_rol->updateInfoCausa($detalleCausa, $rol);
                     $cuadernos = $this->CI->funciones->getCuadernos($data);
                     $nomCuaderno = $cuaderno = $cuadernos[0]['nombre'];
                     $causa_historia = $this->CI->funciones->causaHisotria($data, $nomCuaderno);
                     $this->CI->Busqueda_rol->insertHistoria($causa_historia, $rol);
                     if (count($cuadernos) > 1) {
                         $documento = $this->CI->funciones->getDocument($data);
                         preg_match_all("/(TIP_Cuaderno.value.*')/", $documento, $coincidencias);
                         $arr_tips_cuadernos = $coincidencias[0];
                         preg_match_all("/(CRR_IdCuaderno.value.*)/", $documento, $crr_id);
                         $arr_crr_cuadernos = $crr_id[0];
                         $contador = 0;
                         for ($i = 1; $i < count($cuadernos); $i++) {
                             $postCuaderno[$contador]['tip'] = str_replace("TIP_Cuaderno.value   = '", "", $arr_tips_cuadernos[$i]);
                             $postCuaderno[$contador]['tip'] = str_replace("'", "", $postCuaderno[$contador]['tip']);
                             $postCuaderno[$contador]['crr'] = str_replace("CRR_IdCuaderno.value = '", "", $arr_crr_cuadernos[$i]);
                             $postCuaderno[$contador]['crr'] = str_replace("';", "", $postCuaderno[$contador]['crr']);
                             $postCuaderno[$contador]['crr'] = trim(rtrim($postCuaderno[$contador]['crr'], " "));
                             $postCuaderno[$contador]['gls'] = $cuadernos[$i]['nombre'];
                             $postCuaderno[$contador]['tip_causa'] = $post['TIP_Causa'];
                             $postCuaderno[$contador]['rol_causa'] = $post['ROL_Causa'];
                             $postCuaderno[$contador]['era_causa'] = $post['ERA_Causa'];
                             $postCuaderno[$contador]['cod_tribunal'] = $post['COD_Tribunal'];
                             $contador++;
                         }
                         foreach ($postCuaderno as $cuaderno) {
                             $post_parameters = array('TIP_Causa' => $cuaderno['tip_causa'], 'ROL_Causa' => $cuaderno['rol_causa'], 'ERA_Causa' => $cuaderno['era_causa'], 'COD_Tribunal' => $cuaderno['cod_tribunal'], 'TIP_Cuaderno' => $cuaderno['tip'], 'GLS_Cuaderno' => $cuaderno['gls'], 'CRR_IdCuaderno' => $cuaderno['crr'], 'TIP_Informe' => '1', 'FLG_Caratula' => '0', 'TIP_Cargo' => '2', 'COD_Corte' => '98', 'FLG_ImpresionTribunal' => '1', 'CRR_Cuaderno' => $cuaderno['crr'], 'irAccionAtPublico' => 'Ir a Cuaderno', 'FLG_Vuelta' => 'null');
                         }
                         $cliente->setUri("http://civil.poderjudicial.cl/CIVILPORWEB/AtPublicoDAction.do");
                         $cookies->addCookiesFromResponse($response, $cliente->getUri());
                         $cliente->setParameterPost($post_parameters);
                         $response = $cliente->setMethod('POST')->send();
                         $data = $response->getContent();
                         $nombreCuaderno = $cuaderno['gls'];
                         $historias = $this->CI->funciones->causaHisotria($data, $nombreCuaderno);
                         $this->CI->Busqueda_rol->insertHistoria($historias, $rol);
                     }
                 } else {
                     echo '<pre>';
                     print_r("Ocurrio un problema con la conexion");
                     echo '</pre>';
                 }
             }
         }
     }
 }
Esempio n. 13
0
 function buscaCausas($log, $tabla)
 {
     $client2 = new Client('http://civil.poderjudicial.cl', array('maxredirects' => 100, 'timeout' => 600, 'keepalive' => true));
     $headers = $client2->getRequest()->getHeaders();
     $cookies = new Zend\Http\Cookies($headers);
     $client2->setMethod('GET');
     $response = $client2->send();
     $client2->setUri('http://civil.poderjudicial.cl/CIVILPORWEB/AtPublicoViewAccion.do?tipoMenuATP=1');
     $cookies->addCookiesFromResponse($response, $client2->getUri());
     $response = $client2->send();
     if ($response->isSuccess()) {
         $post2 = $this->setPostBPR($log, $tabla);
         //$contador = 0;
         echo '<pre>POSTS: ' . count($post2) . '</pre>';
         foreach ($post2 as $busqueda2) {
             $rut_dmo = $busqueda2[0];
             $rol = explode('-', $busqueda2[1]);
             $tip_causa = $rol[0];
             $rol_causa = $rol[1];
             $era_causa = $rol[2];
             $cod_tribunal = $busqueda2[2];
             $client2->setUri('http://civil.poderjudicial.cl/CIVILPORWEB/AtPublicoDAction.do');
             $cookies->addCookiesFromResponse($response, $client2->getUri());
             $client2->setParameterPost(array('TIP_Consulta' => '1', 'TIP_Lengueta' => 'tdUno', 'SeleccionL' => '0', 'TIP_Causa' => $tip_causa, 'ROL_Causa' => $rol_causa, 'ERA_Causa' => $era_causa, 'RUC_Era' => '', 'RUC_Tribunal' => '3', 'RUC_Numero' => '', 'RUC_Dv' => '', 'FEC_Desde' => '19/10/2015', 'FEC_Hasta' => '19/10/2015', 'SEL_Litigantes' => '0', 'RUT_Consulta' => '', 'RUT_DvConsulta' => '', 'NOM_Consulta' => '', 'APE_Paterno' => '', 'APE_Materno' => '', 'COD_Tribunal' => $cod_tribunal, 'irAccionAtPublico' => 'Consulta'));
             $response = $client2->setMethod('POST')->send();
             $data = $response->getContent();
             $dom = new Query($data);
             $results = $dom->execute('#contentCellsAddTabla tr');
             $informacionCausas = $this->getCausas($results);
             $postCausas = $this->setPostCausas($informacionCausas);
             $client2->setUri("http://civil.poderjudicial.cl/CIVILPORWEB/ConsultaDetalleAtPublicoAccion.do?");
             $cookies->addCookiesFromResponse($response, $client2->getUri());
             foreach ($postCausas as $post) {
                 $client2->setParameterPost(array("TIP_Consulta" => $post['TIP_Consulta'], "TIP_Cuaderno" => $post['TIP_Cuaderno'], "CRR_IdCuaderno" => $post['CRR_IdCuaderno'], "ROL_Causa" => $post['ROL_Causa'], "TIP_Causa" => $post['TIP_Causa'], "ERA_Causa" => $post['ERA_Causa'], "COD_Tribunal" => $post['COD_Tribunal'], "TIP_Informe" => $post['TIP_Informe'] . "&"));
                 $response = $client2->setMethod('POST')->send();
                 $data = $response->getContent();
                 $dom = new Query($data);
                 $cuadernos = $dom->execute("#TablaCuadernos .comboBox option");
                 $contador = 0;
                 foreach ($cuadernos as $cuaderno) {
                     $arr_cuadernos[$contador]['nombre'] = $cuaderno->textContent;
                     $arr_cuadernos[$contador]['id'] = $cuaderno->attributes->getNamedItem('value')->textContent;
                     $contador++;
                 }
                 $detalleCausa = $dom->execute('tr');
                 $rol = $post['TIP_Causa'] . '-' . $post['ROL_Causa'] . '-' . $post['ERA_Causa'];
                 $arr_detalles = $this->infoCausas($detalleCausa, $busqueda2[1], $rut_dmo);
                 $cuaderno = $arr_cuadernos[0]['nombre'];
                 $litigantes = $dom->execute("#Litigantes table tr");
                 $arr_litigantes = $this->getLitigantes($litigantes, $busqueda2[1], $rut_dmo, $cuaderno);
                 $tribunal = $arr_detalles['tribunal'];
                 $historias = $dom->execute("#Historia tr");
                 $arr_historias = $this->getHistorias($historias, $rol, $rut_dmo, $tribunal, $cuaderno);
                 if (count($cuadernos) > 1) {
                     $documento = $dom->getDocument();
                     preg_match_all("/(TIP_Cuaderno.value.*')/", $documento, $coincidencias);
                     $arr_tips_cuadernos = $coincidencias[0];
                     preg_match_all("/(CRR_IdCuaderno.value.*)/", $documento, $crr_id);
                     $arr_crr_cuadernos = $crr_id[0];
                     $contador = 0;
                     for ($i = 1; $i < count($cuadernos); $i++) {
                         $postCuaderno[$contador]['tip'] = str_replace("TIP_Cuaderno.value   = '", "", $arr_tips_cuadernos[$i]);
                         $postCuaderno[$contador]['tip'] = str_replace("'", "", $postCuaderno[$contador]['tip']);
                         $postCuaderno[$contador]['crr'] = str_replace("CRR_IdCuaderno.value = '", "", $arr_crr_cuadernos[$i]);
                         $postCuaderno[$contador]['crr'] = str_replace("';", "", $postCuaderno[$contador]['crr']);
                         $postCuaderno[$contador]['crr'] = trim(rtrim($postCuaderno[$contador]['crr'], " "));
                         $postCuaderno[$contador]['gls'] = $arr_cuadernos[$i]['nombre'];
                         $postCuaderno[$contador]['tip_causa'] = $post['TIP_Causa'];
                         $postCuaderno[$contador]['rol_causa'] = $post['ROL_Causa'];
                         $postCuaderno[$contador]['era_causa'] = $post['ERA_Causa'];
                         $postCuaderno[$contador]['cod_tribunal'] = $post['COD_Tribunal'];
                         $contador++;
                     }
                     foreach ($postCuaderno as $cuaderno) {
                         echo '<pre>';
                         print_r($cuaderno);
                         echo '</pre>';
                         $post_parameters = array('TIP_Causa' => $cuaderno['tip_causa'], 'ROL_Causa' => $cuaderno['rol_causa'], 'ERA_Causa' => $cuaderno['era_causa'], 'COD_Tribunal' => $cuaderno['cod_tribunal'], 'TIP_Cuaderno' => $cuaderno['tip'], 'GLS_Cuaderno' => $cuaderno['gls'], 'CRR_IdCuaderno' => $cuaderno['crr'], 'TIP_Informe' => '1', 'FLG_Caratula' => '0', 'TIP_Cargo' => '2', 'COD_Corte' => '98', 'FLG_ImpresionTribunal' => '1', 'CRR_Cuaderno' => $cuaderno['crr'], 'irAccionAtPublico' => 'Ir a Cuaderno', 'FLG_Vuelta' => 'null');
                         $client2->setUri("http://civil.poderjudicial.cl/CIVILPORWEB/AtPublicoDAction.do");
                         $cookies->addCookiesFromResponse($response, $client2->getUri());
                         $client2->setParameterPost($post_parameters);
                         $response = $client2->setMethod('POST')->send();
                         $data = $response->getContent();
                         $dom = new Query($data);
                         $cuaderno = $cuaderno['gls'];
                         $tribunal = $arr_detalles['tribunal'];
                         $historias = $dom->execute("#Historia tr");
                         $arr_historias = $this->getHistorias($historias, $rol, $rut_dmo, $tribunal, $cuaderno);
                     }
                 }
             }
         }
     } else {
         echo 'ha ocurrido un problema, por favor dirigase a la pestaña de log y restaure la busuqeda desde el punto en que se detuvo el proceso';
     }
 }
 public function indexAction()
 {
     $client = new HttpClient();
     $client->setAdapter('Zend\\Http\\Client\\Adapter\\Curl');
     $method = $this->params()->fromQuery('method', 'get');
     $client->setUri('http://posterlab.skilla.com/relatori/rest/ejemplo-servidor-restful');
     switch ($method) {
         case 'get-list':
             $client->setMethod('GET');
             break;
         case 'get':
             $client->setMethod('GET');
             $client->setParameterGET(array('id' => 4));
             break;
         case 'create':
             $client->setMethod('POST');
             $client->setParameterPOST(array('data' => 'Programacion Java SE'));
             break;
         case 'update':
             $data = array('data' => 'Curso Spring Framework');
             $adapter = $client->getAdapter();
             $adapter->connect('posterlab.skilla.com', 80);
             $uri = $client->getUri() . '/2';
             // Enviamos con Method PUT, con el parametro $data
             $adapter->write('PUT', new \Zend\Uri\Uri($uri), 1.1, array(), http_build_query($data));
             $responsecurl = $adapter->read();
             list($headers, $content) = explode("\r\n\r\n", $responsecurl, 2);
             $response = $this->getResponse();
             $response->getHeaders()->addHeaderLine('content-type', 'application/json; charset=utf-8');
             $response->setContent($content);
             return $response;
         case 'delete':
             $adapter = $client->getAdapter();
             $adapter->connect('posterlab.skilla.com', 80);
             $uri = $client->getUri() . '/1';
             //enviamos param id = 1
             // Enviamos con Method DELETE
             $adapter->write('DELETE', new \Zend\Uri\Uri($uri), 1.1, array());
             $responsecurl = $adapter->read();
             list($headers, $content) = explode("\r\n\r\n", $responsecurl, 2);
             $response = $this->getResponse();
             $response->getHeaders()->addHeaderLine('content-type', 'application/json; charset=utf-8');
             $response->setContent($content);
             return $response;
         default:
             $client->setMethod('GET');
             break;
     }
     //enviamos get/get-list/create
     $response = $client->send();
     if (!$response->isSuccess()) {
         // reportamos la falla
         $message = $response->getStatusCode() . ': ' . $response->getReasonPhrase();
         $response = $this->getResponse();
         $response->setContent($message);
         return $response;
     }
     $body = $response->getBody();
     $response = $this->getResponse();
     $response->setContent($body);
     return $response;
 }
Esempio n. 15
0
 protected function setUp()
 {
     $zendHttpClient = new ZendHttpClient();
     $zendHttpClient->getUri()->setHost('api.localhost');
     $this->client = new HttpClient($zendHttpClient);
 }
Esempio n. 16
0
 /**
  * Send a request and return the response.
  *
  * @param \Zend\Http\Client $client Prepare HTTP client
  *
  * @return string Response body
  *
  * @throws \VuFindSearch\Backend\Exception\RemoteErrorException  Server
  * signaled a server error (HTTP 5xx)
  * @throws \VuFindSearch\Backend\Exception\RequestErrorException Server
  * signaled a client error (HTTP 4xx)
  */
 protected function send(\Zend\Http\Client $client)
 {
     $this->debug(sprintf('=> %s %s', $client->getMethod(), $client->getUri()));
     $time = microtime(true);
     $response = $client->send();
     $time = microtime(true) - $time;
     $this->debug(sprintf('<= %s %s', $response->getStatusCode(), $response->getReasonPhrase()), ['time' => $time]);
     if (!$response->isSuccess()) {
         throw HttpErrorException::createFromResponse($response);
     }
     return $response->getBody();
 }
Esempio n. 17
0
 /**
  * Proxify an existing client.
  *
  * Returns the client given as argument with appropriate proxy setup.
  *
  * @param \Zend\Http\Client $client  HTTP client
  * @param array             $options ZF2 ProxyAdapter options
  *
  * @return \Zend\Http\Client
  */
 public function proxify(\Zend\Http\Client $client, array $options = array())
 {
     if ($this->proxyConfig) {
         $host = $client->getUri()->getHost();
         if (!$this->isLocal($host)) {
             $proxyType = isset($this->proxyConfig['proxy_type']) ? $this->proxyConfig['proxy_type'] : 'default';
             if ($proxyType == 'socks5') {
                 $adapter = new \Zend\Http\Client\Adapter\Curl();
                 $host = $this->proxyConfig['proxy_host'];
                 $port = $this->proxyConfig['proxy_port'];
                 $adapter->setCurlOption(CURLOPT_FOLLOWLOCATION, true);
                 $adapter->setCurlOption(CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
                 $adapter->setCurlOption(CURLOPT_PROXY, $host);
                 if (isset($port) && !empty($port)) {
                     $adapter->setCurlOption(CURLOPT_PROXYPORT, $port);
                 }
                 $client->setAdapter($adapter);
             } elseif ($proxyType == 'default') {
                 $adapter = new \Zend\Http\Client\Adapter\Proxy();
                 $options = array_replace($this->proxyConfig, $options);
                 $adapter->setOptions($options);
                 $client->setAdapter($adapter);
             }
         }
     }
     return $client;
 }
Esempio n. 18
0
 /**
  * Proxify an existing client.
  *
  * Returns the client given as argument with appropriate proxy setup.
  *
  * @param \Zend\Http\Client $client  HTTP client
  * @param array             $options ZF2 ProxyAdapter options
  *
  * @return \Zend\Http\Client
  */
 public function proxify(\Zend\Http\Client $client, array $options = [])
 {
     if ($this->proxyConfig) {
         $host = $client->getUri()->getHost();
         if (!$this->isLocal($host)) {
             $proxyType = isset($this->proxyConfig['proxy_type']) ? $this->proxyConfig['proxy_type'] : 'default';
             if ($proxyType == 'socks5') {
                 $adapter = new \Zend\Http\Client\Adapter\Curl();
                 // Apply standard proxy options for Curl adapter:
                 $this->setCurlProxyOptions($adapter);
                 // Add SOCKS5 settings:
                 $adapter->setCurlOption(CURLOPT_FOLLOWLOCATION, true);
                 $adapter->setCurlOption(CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
                 $client->setAdapter($adapter);
             } elseif ($proxyType == 'default') {
                 // If the user has manually configured a Curl adapter,
                 // configure it for proxy compatibility; otherwise, create
                 // a fresh Proxy adapter.
                 if ($this->hasCurlAdapterAsDefault()) {
                     $adapter = new \Zend\Http\Client\Adapter\Curl();
                     $this->setCurlProxyOptions($adapter);
                 } else {
                     $adapter = new \Zend\Http\Client\Adapter\Proxy();
                     $options = array_replace($this->proxyConfig, $options);
                     $adapter->setOptions($options);
                 }
                 $client->setAdapter($adapter);
             }
         }
     }
     return $client;
 }
 /**
  *
  * @param string $url
  * @return insatnce of Zend\Http\Client
  */
 protected function getNewResponse($url = NULL)
 {
     $client = new HttpClient();
     /**
      * Incase of 2nd call , use product url
      */
     if ($url != NULL) {
         $client->setUri($url);
     }
     /**
      * check if it is 2nd call then use the header cookies so that we can use the same session to avoid
      */
     /**
      * sending more traffic to the site for the performance point of view
      */
     if (isset($_SESSION['cookiejar']) && $_SESSION['cookiejar'] instanceof \Zend\Http\Cookies) {
         $cookieJar = $_SESSION['cookiejar'];
     } else {
         // set Curl Adapter
         $client->setAdapter('Zend\\Http\\Client\\Adapter\\Curl');
         // $response = $this->getResponse ();
         // keep the conntection alive for multiple calls
         $client->setOptions(array('keepalive' => true));
         // set content-type
         // $httpResponse->getHeaders ()->addHeaderLine ( 'content-type', 'text/html; charset=utf-8' );
         $client->setUri(SELF::GROCCERYURL);
         $result = $client->send();
         $cookieJar = \Zend\Http\Cookies::fromResponse($result, SELF::GROCCERYURL);
         $_SESSION['cookiejar'] = $cookieJar;
         $client->resetParameters();
         return $result;
     }
     $connectionCookies = $cookieJar->getMatchingCookies($client->getUri());
     // set the cookies for the 2nd call
     $client->setCookies($this->getConntetionCookies($connectionCookies));
     $response = $client->send();
     return $response;
 }