Esempio n. 1
0
 /**
  * login
  * 执行的过程中绝不能产生语法异常,也不能有不可预知的异常抛出
  * 
  * 值得重试的可选项:连接超时,读取超时,其它合理的错误返回
  * 这些都是有一定随机性的。以下两种情况不要重试了:
  * 1.不强制一定有正确结果返回
  * 2.重试成功的可能性小或没有
  * 
  * 重试:
  * 1.意外:超时,断线
  * 2.随机返回
  */
 public static function login2($data = [])
 {
     $i = 50;
     while ($i > 0) {
         $content = Api::getHttp()->get('http://yii.app.com/login.html', $data)->getContent();
         //返回成功
         if ($content == 'ok') {
             return 'ok';
             //可以重试,有随机性
         } elseif ($content == 'ng2') {
             $i--;
             continue;
             //不必试了
         } else {
             return null;
         }
     }
     return null;
 }
Esempio n. 2
0
<?php

/**
 * @link https://github.com/yxdj
 * @copyright Copyright (c) 2014 xuyuan All rights reserved.
 * @author xuyuan <*****@*****.**>
 */
//composer autoload
require dirname(dirname(dirname(__DIR__))) . '/autoload.php';
use yxdj\network\Api;
use yxdj\network\Cli;
$args = Cli::parseArgs($argv, $argc);
echo Api::getStream()->request(['method' => 'POST', 'url' => 'http://192.168.1.59:37/test_s.php', 'row' => ['Xuyuan' => 'test'], 'get' => ['get1' => 'param2', 'get2' => ['a' => 'param2a', 'b' => 'param2b']], 'post' => ['post1' => 'param2', 'post2' => ['a' => 'param2a', 'b' => 'param2b']], 'cookie' => ['cookie1' => 'param2', 'cookie2' => ['a' => 'param2a', 'b' => 'param2b']]])->getContent();
Esempio n. 3
0
require dirname(dirname(dirname(__DIR__))) . '/autoload.php';
use yxdj\network\Api;
use yxdj\network\Cli;
$args = Cli::parseArgs($argv, $argc);
/*
if (empty($args['s'])) {
    exit('please input `-s`.');
}

$uploadfile = $args['s'];
*/
if ($argc < 2 || empty($argv[1])) {
    exit('Error: please input download file');
}
$downloadfile = $downloadfile_o = $argv[1];
/*
$uploadfile = Cli::ask('please input path for upload file:');
//print_r($args);exit;

$uploadfile = './' .$uploadfile; 
*/
$data = Api::getStream()->request(['method' => 'POST', 'url' => 'http://192.168.1.59:37/test_server.php', 'row' => ['Xuyuan' => 'test'], 'get' => ['get1' => 'param2', 'get2' => ['a' => 'param2a', 'b' => 'param2b']], 'post' => ['type' => 'download', 'download' => $downloadfile], 'cookie' => ['cookie1' => 'param2', 'cookie2' => ['a' => 'param2a', 'b' => 'param2b']]])->getContent();
if ($data == '######') {
    echo 'not fond this file!';
    exit;
}
if (file_put_contents(basename($downloadfile), $data)) {
    echo 'ok';
} else {
    echo 'ng';
}
Esempio n. 4
0
 public static function login($data)
 {
     $url = 'http://test/login.php';
     $username = isset($data['username']) ? $data['username'] : '';
     $password = isset($data['password']) ? $data['password'] : '';
     $user = ['username' => $username, 'password' => md5($password)];
     $content = Api::getHttp()->post($url, $user)->getContent();
     $result = json_decode($content, true);
     if (isset($result['status'])) {
         if ($result['status'] == 'ok') {
             return $result['data']['info'];
         } elseif ($result['status'] == 'ng') {
             return $result['error'];
         }
     }
     //如有需要可以在此根据请求对象中的信息调试或判断处理
     return 'unknow error!';
 }
Esempio n. 5
0
//composer autoload
require dirname(dirname(dirname(__DIR__))) . '/autoload.php';
use yxdj\network\Api;
use yxdj\network\Cli;
$args = Cli::parseArgs($argv, $argc);
/*
if (empty($args['s'])) {
    exit('please input `-s`.');
}

$uploadfile = $args['s'];
*/
if ($argc < 2 || empty($argv[1])) {
    exit('Error: please input upload file');
}
$uploadfile = $uploadfile_o = $argv[1];
/*
$uploadfile = Cli::ask('please input path for upload file:');
//print_r($args);exit;

$uploadfile = './' .$uploadfile; 
*/
if (!is_file($uploadfile)) {
    $uploadfile = './' . $uploadfile;
    if (!is_file($uploadfile)) {
        exit("not find this file: " . $uploadfile_o);
    }
}
$filename = basename($uploadfile);
echo Api::getStream()->request(['method' => 'POST', 'url' => 'http://192.168.1.59:37/test_server.php', 'row' => ['Xuyuan' => 'test'], 'get' => ['get1' => 'param2', 'get2' => ['a' => 'param2a', 'b' => 'param2b']], 'post' => ['post1' => 'param2', 'post2' => ['a' => 'param2a', 'b' => 'param2b']], 'cookie' => ['cookie1' => 'param2', 'cookie2' => ['a' => 'param2a', 'b' => 'param2b']], 'file' => ['file1' => ['name' => $filename, 'value' => file_get_contents($uploadfile)]]])->getContent();