Leser: 17
get '/' => {text => 'Hello World!'};
my $file = $self->param('upspot');
QuoteWas sagt ihr dazu?
2018-08-24T14:49:02 GwenDragonNa, es steht dir frei, was auf CPAN hoch zu laden, um uns Programmierenden eine verbesserte CGI-Version zu geben.
2018-09-04T16:12:58 rostiMeine CPAN Module findest Du unter meinem Benutzernamen pilgrim.
2018-09-04T13:53:15 rostiNun, das Interesse an meinen Entwicklungen kann ich auch anhand dieses Threads festmachen: File Upload Datenstruktur
Das sieht für mich so aus, als ob es auf CPAN schon alles gibt und kein weiterer Bedarf diesbezüglich besteht. Wobei ich eine solche Einstellung 1. ziemlich bedauerlich finde und 2. gar nicht nachvollziehen kann.
MfG
QuoteWenn Du vor dem Veröffentlichen das Modul diskutieren willst, könntest Du das auf http://prepan.org/ tun...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
package CGIX; use strict; use warnings; use URI::Escape; sub new { my($class,@initializer) = @_; my $self = {}; $self->{header} = []; parse_QUERY_STRING(\$self); parse_HTTP_COOKIE(\$self); bless $self; return $self; } sub header { my $self = shift(); return join("\r\n", @{$self->{header}}), "\r\n\r\n"; } sub add_header{ my ($self, $new) = @_; push( @{$self->{header}}, $new ); } sub set_cookie { my ($self, $p) = @_; my $cs = ""; if( defined $p->{-name} && defined $p->{-value} ){ $cs .= "Set-Cookie: ".$p->{-name}."=".uri_escape($p->{-value}); if( defined $p->{-expires} ){ $cs .= "; Expires=".expires( $p->{-expires}, "cookie" ); } if( defined $p->{-path} ){ $cs .= "; Path=".$p->{-path}; } push( @{$self->{header}}, $cs ); } } sub param { my ($self, $param, $default) = @_; if( defined $self->{get}->{$param} ){ return $self->{get}->{$param}; } return $default; } sub cookie { my ($self, $param, $default) = @_; if( defined $self->{cookie}->{$param} ){ return $self->{cookie}->{$param}; } return $default; } sub parse_QUERY_STRING { my $self = shift; my @values = split(/\&/,$ENV{QUERY_STRING}); foreach (@values) { my ($paramname, $data) = split(/=/, $_); $$self->{get}->{$paramname} = $data; } } sub parse_HTTP_COOKIE { my $self = shift; my @values = split(/\;/,$ENV{HTTP_COOKIE}); foreach (@values) { my ($paramname, $data) = split(/=/, $_); $$self->{cookie}->{$paramname} = uri_unescape($data); } } sub expires { my($time,$format) = @_; $format ||= 'http'; my(@MON)=qw/Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec/; my(@WDAY) = qw/Sun Mon Tue Wed Thu Fri Sat/; # pass through preformatted dates for the sake of expire_calc() $time = expire_calc($time); return $time unless $time =~ /^\d+$/; # make HTTP/cookie date string from GMT'ed time # (cookies use '-' as date separator, HTTP uses ' ') my($sc) = ' '; $sc = '-' if $format eq "cookie"; my($sec,$min,$hour,$mday,$mon,$year,$wday) = gmtime($time); $year += 1900; return sprintf("%s, %02d$sc%s$sc%04d %02d:%02d:%02d GMT", $WDAY[$wday],$mday,$MON[$mon],$year,$hour,$min,$sec); } # This internal routine creates an expires time exactly some number of # hours from the current time. It incorporates modifications from # Mark Fisher. sub expire_calc { my($time) = @_; my(%mult) = ('s'=>1, 'm'=>60, 'h'=>60*60, 'd'=>60*60*24, 'M'=>60*60*24*30, 'y'=>60*60*24*365); # format for time can be in any of the forms... # "now" -- expire immediately # "+180s" -- in 180 seconds # "+2m" -- in 2 minutes # "+12h" -- in 12 hours # "+1d" -- in 1 day # "+3M" -- in 3 months # "+2y" -- in 2 years # "-3m" -- 3 minutes ago(!) # If you don't supply one of these forms, we assume you are # specifying the date yourself my($offset); if (!$time || (lc($time) eq 'now')) { $offset = 0; } elsif ($time=~/^\d+/) { return $time; } elsif ($time=~/^([+-]?(?:\d+|\d*\.\d*))([smhdMy])/) { $offset = ($mult{$2} || 1)*$1; } else { return $time; } my $cur_time = time; return ($cur_time+$offset); } 1;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
use CGIX; # GET-Parameter holen (Der 2. übergebene Wert ist der default wert, falls es den Parameter in der url nicht gibt) my $page = $cgix->param("page",""); my $subpage = $cgix->param("subpage",""); my $app = $cgix->param("app",0); my $pagenum = $cgix->param("pagenum",""); # cookie holen my $cookie = $cgix->cookie( "page" ); #Header $cgix->add_header("Content-Type: text/html; charset=ISO-8859-1"); $cgix->set_cookie( {-name=>"page", -expires=>"+99y", -value=>"cookievalue", -path=>'/'} ); print $cgix->header();
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
# Public und unabhängig verwendbar # application/x-www-form-urlencoded sub qparse{ my $self = shift; my $rawdata = shift; my %param = (); # Punkte in Parameternamen erlauben my @pie = split /[;&]/, $rawdata; foreach my $p(@pie){ my ($pname, $val) = split(/=/, $p, 2); next unless $pname; next unless defined $val; $val =~ s/\+/ /g; $val =~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg; push @{$param{$pname}}, $val; } return \%param; }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// POST VAIABLES
var obst = { bananen : "", aepfel : "" }
obst.bananen = ["Dessertbanane", "Babybanane", "Faserbanane"]
obst.aepfel = ["Renette", "Boikenapfel", "Gewürzluiken"]
var gemuese = ["Brokoli", "Spinat", "Wirsing"]
var array = [];
array.push(obst);
array.push(gemuese);
var array_ips = [ "127.0.0.1","localhost" ]
var postdata = { IsMobil : 0, sorten : array, ips : array_ips, ClientIP : "123.123.123.123" }
$.ajax({ url : "index.pl",
async : false,
data : postdata,
type : 'POST',
success : function(result){
$(".result").html(result);
}
});
1 2 3 4 5 6 7 8 9
if( $ENV{CONTENT_LENGTH} ){ read(STDIN, my $content, $ENV{CONTENT_LENGTH}); my @paras = split(/&/, uri_unescape($content)); print "PARAMETER:<br/>"; foreach(@paras){ print $_."<br/>"; } print "<br />CONTENTTYPE: ".$ENV{'CONTENT_TYPE'}; }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
PARAMETER:
IsMobil=0
sorten[0][bananen][]=Dessertbanane
sorten[0][bananen][]=Babybanane
sorten[0][bananen][]=Faserbanane
sorten[0][aepfel][]=Renette
sorten[0][aepfel][]=Boikenapfel
sorten[0][aepfel][]=Gewürzluiken
sorten[1][]=Brokoli
sorten[1][]=Spinat
sorten[1][]=Wirsing
ips[]=127.0.0.1
ips[]=localhost
ClientIP=123.123.123.123
CONTENTTYPE: application/x-www-form-urlencoded; charset=UTF-8
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
sub parse_params { my $self = shift; my @values = split(/\&/,$ENV{QUERY_STRING}); foreach (@values) { my ($paramname, $data) = split(/=/, $_); $$self->{get}->{$paramname} = $data; } if( $ENV{CONTENT_LENGTH} ){ read(STDIN, my $content, $ENV{CONTENT_LENGTH}); my @paras = split(/&/, uri_unescape($content)); foreach(@paras){ (my $var, my $value) = split(/=/, $_); if( $var =~ /^(\w+)$/ ){ $$self->{post}->{$1} = $value; } if( $var =~ /(\w+)\[\]/ ){ if( defined $$self->{post}->{$1} ){ push( @{ $$self->{post}->{$1} }, $value ); } else{ my @array = ( $value ); $$self->{post}->{$1} = \@array; } } } } }
QuoteVon daher nenne auch kein Attribut POST oder GET, sowas machen PHP Fuzzies. Deine Logik ist falsch
Quoteaber wie gesagt könnte es den Parameternamen im STDIN und im Querystring doppelt geben.
Quoteund stelle die Original Datenstruktur wieder her.
QuoteUnd genau da habe ich ja das Problem eine Methode zu schreiben die mir genau die gleiche Datenstruktur aufbaut wie das json das ich in js übergebe.
use JSON;
{ "auth": {"tenantName":"****", "passwordCredentials": {"username":"****","password":"****"} }}
1 2 3 4 5 6 7 8
# Cookie-String Parsen # $ENV{HTTP_COOKIE} sub cookie_parse{ my $self = shift; my $cookies = shift || $ENV{HTTP_COOKIE} || ''; my %pie = map { /(\w+)=(.*)/ } split /;\s+/, $cookies; return \%pie; }