利用curl向页面发送cookie进行单元测试

发表于:2009-12-18来源:作者:点击数: 标签:
利用curl向页面发送cookie进行单元测试 单元测试代码 (1)apache配置: DocumentRoot /home/work/web ServerName 127.0.0.1 # 注意,设成ip (2)页面文件 /home/work/web/hello.php echo "hello,world!\n"; $strCookie1 = $_COOKIE["hello1"] ; $strCookie2 =

  利用curl向页面发送cookie进行单元测试   单元测试代码

  (1)apache配置:

  DocumentRoot /home/work/web

  ServerName 127.0.0.1

  # 注意,设成ip

  (2)页面文件

  /home/work/web/hello.php

  

  echo "hello,world!\n";

  $strCookie1 = $_COOKIE["hello1"] ;

  $strCookie2 = $_COOKIE["hello2"] ;

  $strCookie3 = $_COOKIE["hello3"] ;

  $strCookie4 = $_COOKIE["hello4"] ;

  echo "$strCookie1\n";

  echo "$strCookie2\n";

  echo "$strCookie3\n";

  echo "$strCookie4\n";

  echo "end hello,world!\n";

  ?>

  (3)发送cookie测试

  curl http://127.0.0.1/hello.php -b "hello1=111;hello2=222;hello3=333;hello4=444"

  注:-b参数表示发送cookie,具体curl用法参见curl --help或百度之;

  cookie用引号引起来,多个cookie之间用分号分隔。

  (4)也可以这样发送

  

  $cookie = "hello1=111;hello2=222;hello3=333;hello4=444";

  $c = curl_init("http://127.0.0.1/hello.php");

  curl_setopt ($c, CURLOPT_COOKIE , $cookie );

  curl_exec($c);

  curl_close($c);

  ?>

原文转自:http://www.ltesting.net