perl 定义post接口
[root@wx03 mojo]# cat a1.pl
use Digest::MD5;
my $md5 = Digest::MD5->new;
$md5->add(1234567);
print $md5->hexdigest."\n";
[root@wx03 mojo]# perl a1.pl
fcea920f7412b5da7be0cf42b8c93759 [root@wx03 mojo]# cat a1.pl
use Digest::MD5;
my $md5 = Digest::MD5->new;
$md5->add(admin);
print $md5->hexdigest."\n";
[root@wx03 mojo]# perl a1.pl
21232f297a57a5a743894a0e4a801fc3 [root@wx03 mojo]# cat a1.pl
use Digest::MD5;
my $md5 = Digest::MD5->new;
$md5->add(admin);
my $pass= $md5->hexdigest;
print "\$pass is $pass\n";
[root@wx03 mojo]# perl a1.pl
$pass is 21232f297a57a5a743894a0e4a801fc3 mysql> select md5('admin') from user;
+----------------------------------+
| md5('admin') |
+----------------------------------+
| 21232f297a57a5a743894a0e4a801fc3 |
| 21232f297a57a5a743894a0e4a801fc3 | mysql> select md5('1234567') from user;
+----------------------------------+
| md5('1234567') |
+----------------------------------+
| fcea920f7412b5da7be0cf42b8c93759 |
| fcea920f7412b5da7be0cf42b8c93759 | /*************************************
[root@wx03 mojo]# cat login.pl
use Mojolicious::Lite;
use JSON qw/encode_json decode_json/;
use Encode;
no strict;
no warnings;
use JSON;
use POSIX;
use JSON::RPC::Client;
use Data::Dumper;
use Digest::MD5;
my $SDATE = strftime("%Y-%m-%d",localtime());
post '/api/login' => sub {
my $c = shift;
my $username = $c->param('username');
my $paswd = $c->param('passwd');
my $md5 = Digest::MD5->new;
$md5->add($passwd);
$passwd= $md5->hexdigesta;
print "\$passwd is $passwd\n";
use DBI;
my %hash=();
my $dbUser='DEVOPS';
my $user="root";
my $pass='R00t,uHagt.0511';
my $dbh = DBI->connect("dbi:mysql:database=$dbUser;host=127.0.0.1;port=3306",$user,$pass) or die "can't connect to database ". DBI-errstr;
my $hostSql = qq{select count(*) from user where username='$username' and password='$passwd'};
my $selStmt = $dbh->prepare($hostSql);
print "\$hostSql is $hostSql\n";
$selStmt->execute();
my $count = $selStmt->fetchrow_array();
print "\$count is $count\n";
if ( $count ==1 )
{ $hash{login}='success';$c->render(json => \%hash);}
else
{ $hash{login}='failed';$c->render(json => \%hash);}
};
app->start; [root@wx03 mojo]#
[root@wx03 mojo]# morbo login.pl
Server available at http://127.0.0.1:3000 模拟post 请求: Pattern Methods Name /api/login POST apilogin /**********get 登录: [root@wx03 mojo]# cat login.pl
use Mojolicious::Lite;
use JSON qw/encode_json decode_json/;
use Encode;
no strict;
no warnings;
use JSON;
use POSIX;
use JSON::RPC::Client;
use Data::Dumper;
use Digest::MD5;
my $SDATE = strftime("%Y-%m-%d",localtime());
get '/api/login' => sub {
my $c = shift;
my $username = $c->param('username');
my $passwd = $c->param('passwd');
my $md5 = Digest::MD5->new;
$md5->add($passwd);
$passwd= $md5->hexdigest;
print "\$passwd is $passwd\n";
use DBI;
my %hash=();
my $dbUser='DEVOPS';
my $user="root";
my $pass='R00t,uHagt.0511';
my $dbh = DBI->connect("dbi:mysql:database=$dbUser;host=127.0.0.1;port=3306",$user,$pass) or die "can't connect to database ". DBI-errstr;
my $hostSql = qq{select count(*) from user where username='$username' and password='$passwd'};
my $selStmt = $dbh->prepare($hostSql);
print "\$hostSql is $hostSql\n";
$selStmt->execute();
my $count = $selStmt->fetchrow_array();
print "\$count is $count\n";
if ( $count ==1 )
{ $hash{login}='success';$c->render(json => \%hash);}
else
{ $hash{login}='failed';$c->render(json => \%hash);}
};
app->start; http://120.55.118.6:3000/api/login?username=admin&passwd=admin
{"login":"success"} http://120.55.118.6:3000/api/login?username=admin&passwd=admin33
{"login":"failed"} /*******post 登录 [tomcat@wx03 ~]$ perl a3.pl
---------------
200 OK
[tomcat@wx03 ~]$ vim a3.pl
[tomcat@wx03 ~]$ perl a3.pl
---------------
200 OK
HTTP/1.1 200 OK
Date: Fri, 21 Oct 2016 04:40:38 GMT
Server: Mojolicious (Perl)
Content-Length: 19
Content-Type: application/json;charset=UTF-8
Client-Date: Fri, 21 Oct 2016 04:40:38 GMT
Client-Peer: 120.55.118.6:3000
Client-Response-Num: 1 {"login":"success"}
[tomcat@wx03 ~]$ cat a3.pl
use LWP::UserAgent;
use HTTP::Cookies;
use HTTP::Headers;
use HTTP::Response;
use Encode;
use File::Temp qw/tempfile/;
use HTTP::Date qw(time2iso str2time time2iso time2isoz);
my $CurrTime = time2iso(time());
my $dis_mainpublish='中均资本';
my $ua = LWP::UserAgent->new;
$ua->timeout(10);
$ua->env_proxy;
my $now = time();
$ua->agent('Mozilla/5.0');
my $cookie_jar = HTTP::Cookies->new( file => 'lwp_cookies.txt',
autosave => 1,
ignore_discard => 1
);
$ua->cookie_jar($cookie_jar);
my $str=(rand(1));
my $url='http://120.55.118.6:3000/api/login';
my $res = $ua->post($url,{
'username'=>'admin',
'passwd'=>'admin'
}
);
print "---------------\n";
print $res->status_line."\n";
print $res->as_string();
[tomcat@wx03 ~]$ perl a3.pl
---------------
200 OK
HTTP/1.1 200 OK
Date: Fri, 21 Oct 2016 04:40:43 GMT
Server: Mojolicious (Perl)
Content-Length: 19
Content-Type: application/json;charset=UTF-8
Client-Date: Fri, 21 Oct 2016 04:40:43 GMT
Client-Peer: 120.55.118.6:3000
Client-Response-Num: 1 {"login":"success"} [tomcat@wx03 ~]$ perl a3.pl
---------------
200 OK
HTTP/1.1 200 OK
Date: Fri, 21 Oct 2016 04:40:43 GMT
Server: Mojolicious (Perl)
Content-Length: 19
Content-Type: application/json;charset=UTF-8
Client-Date: Fri, 21 Oct 2016 04:40:43 GMT
Client-Peer: 120.55.118.6:3000
Client-Response-Num: 1 {"login":"success"}
[tomcat@wx03 ~]$ vim a3.pl
[tomcat@wx03 ~]$ perl a3.pl
---------------
200 OK
HTTP/1.1 200 OK
Date: Fri, 21 Oct 2016 04:41:19 GMT
Server: Mojolicious (Perl)
Content-Length: 18
Content-Type: application/json;charset=UTF-8
Client-Date: Fri, 21 Oct 2016 04:41:19 GMT
Client-Peer: 120.55.118.6:3000
Client-Response-Num: 1 {"login":"failed"}
perl 定义post接口的更多相关文章
- java中接口的定义和接口的实现
1.接口的定义 使用interface来定义一个接口.接口定义同类的定义类似,也是分为接口的声明和接口体,其中接口体由常量定义和方法定义两部分组成.定义接口的基本格式如下: [修饰符] interfa ...
- 定义 ICache 接口,以及实现默认的 ASP.NET 缓存机制
本文定义 ICache 接口,以及实现默认的 ASP.NET 缓存机制(即通过 System.Web.Caching.Cache)来缓存,将来也可以通过扩展,替换默认实现. 下面直接贴代码了: ICa ...
- [二] java8 函数式接口详解 函数接口详解 lambda表达式 匿名函数 方法引用使用含义 函数式接口实例 如何定义函数式接口
函数式接口详细定义 package java.lang; import java.lang.annotation.*; /** * An informative annotation type use ...
- C++:如何正确的定义一个接口类
C++中如何定义接口类?首先给接口类下了定义:接口类应该是只提供方法声明,而自身不提供方法定义的抽象类.接口类自身不能实例化,接口类的方法定义/实现只能由接口类的子类来完成. 而对于C++,其接口类一 ...
- 二十三、DBMS_METADATA(提供提取数据库对象的完整定义的接口)
1.概述 作用:提供提取数据库对象的完整定义的接口.这些定义可以用XML或SQL DDL格式描述.提供两种类型接口:可编程控制的接口:用于Ad Hoc查询的简单接口. 2.包的组成 dbms_meta ...
- 如何定义一个接口(接口Interface只在COM组件中定义了,MFC和C++都没有接口的概念)
接口是COM中的关键词,在c++中并没有这个概念.接口是一种极度的抽象.接口用在COM组件中有自己的GUID值,因此定义接口时一定要指定它的GUID值. 实际上接口就是struct,即#define ...
- java8函数式接口详解、函数接口详解、lambda表达式匿名函数、方法引用使用含义、函数式接口实例、如何定义函数式接口
函数式接口详细定义 函数式接口只有一个抽象方法 由于default方法有一个实现,所以他们不是抽象的. 如果一个接口定义了一个抽象方法,而他恰好覆盖了Object的public方法,仍旧不算做接口的抽 ...
- java抽象类,接口(接口定义,实现接口,instanceof运算符,对象转换)
抽象类 在面向对象的概念中,所有的对象都是通过类来表述的,但并不是所有的类都能够完整的描绘对象,如果一个类中没有包含足够的信息来描绘一类具体的对象,这样的类就是抽象类.抽象类往往用来表征对问题领域进行 ...
- Java 基础 面向对象: 接口(interface )概念 以及接口之练习3 -定义一个接口用来实现两个对象的比较并 判断instanceof是否为同类
接口(interface )概念概念笔记 及测试代码: /** 面向对象: 接口(interface ) 是与类并行的一个概念: * 1.接口可以看成一个特殊的抽象类,它是常量与抽象方法的一个集合 * ...
随机推荐
- Qt 学习之路:Canvas
在 QML 刚刚被引入到 Qt 4 的那段时间,人们往往在讨论 Qt Quick 是不是需要一个椭圆组件.由此,人们又联想到,是不是还需要其它的形状?这种没玩没了的联想导致了一个最直接的结果:除了圆角 ...
- MyEclipse_6.0.1GA_E3.3.1集成版下载地址
因在开发中经常使用到myeclipse 对比相关版本,还是觉得6.0 –6.5 比较适合开发,其他的开发起来比较卡,下面是下载地址 MyEclipse_6.0.1GA_E3.3.1集成版下载地址: ...
- iOS-本地推送(本地通知)
第一步:注册本地通知: // 设置本地通知 + (void)registerLocalNotification:(NSInteger)alertTime { UILocalNotification * ...
- float:left 与display:inline的具体区别?
设了float:left的元素允许它的右边存在任何元素同行显示,不论是内联元素还是块元素.但它的左边还是不允许存在任何元素与之同行显示,哪怕其它的元素的代码在前,除非也给前面的元素加上float:le ...
- PRD产品需求文档概要
PRD概念 PRM就是Product Requirements Document的简称,也就是产品需求模型.一般来说一个产品会伴随有市场需求文档(Market Requirements Documen ...
- Maven学习总结——聚合与继承
一.聚合 如果我们想一次构建多个项目模块,那我们就需要对多个项目模块进行聚合 1.1.聚合配置代码 1 <modules> 2 <module>模块一</module&g ...
- Android 实现闹钟功能
原文地址:Android 实现闹钟功能作者:Android_Learners 一.手机闹钟主要用到了AlarmManager类,AlarmManager类提供了访问系统定时服务的途径,开发人员可以 ...
- SQL觸發器聯級刪除
Create TRIGGER [dbo].[trigInstructionsDelete] ON dbo.Instructions instead OF DELETE AS BEGIN DECLARE ...
- UIAlertController (UIActionSheet, UIAlertView is deprecated in iOS 8.)
iOS 8 后 UIAlertView 和 UIActionSheet 都被合并到了 UIAlertController里面. 文档原文: Important: UIAlertView is dep ...
- 【转】 iOS开发之手势gesture详解
原文:http://www.cnblogs.com/salam/archive/2013/04/30/iOS_gesture.html 前言 在iOS中,你可以使用系统内置的手势识别 (Gesture ...