- 论坛徽章:
- 6
|
本帖最后由 只是一个红薯 于 2013-04-27 18:37 编辑
现遇到一个问题,从多行文本Text()读取的json数据接收后不知道是什么格式
接口取不到参数,代码如下:- use 5.016;
- use strict;
- use autodie;
- use Mojo::UserAgent;
- use Tk;
- my $ua = Mojo::UserAgent->new;
- my $mw=MainWindow->new;
- $mw->geometry("800x600");
- my $main_frame = $mw->Frame(-background => "white")->pack(-side => 'top', -fill => 'x');
- my $left_frame = $main_frame->Frame(-background => "white")->pack(-anchor=>"nw", -ipadx=>"35");
- my $right_frame = $main_frame->Frame(-background => "white")->pack(-anchor=>"ne");
- my $bottom_frame= $main_frame->Frame(-background=>"white",-width=>"5")->pack(-side=>"bottom",-fill=>'x');
- $bottom_frame->Label(-text=>"output:",-background=>"white")->pack(-side=>"left");
- my $output_text=$bottom_frame->Text(-background => "white", -foreground => "black")->pack(-side => "bottom");
- $left_frame->Label(-text => "Url", -background => "white", -foreground => "black")->pack(-side => "left");
- $right_frame->Label(-text => "input_json", -background => "white", -foreground => "black")->pack(-side => "left");
- my $url_entry = $left_frame->Entry(-background => "white", -foreground => "red",-width=>"70")->pack(-side => "left");
- my $post_button = $left_frame->Button(-text => "post", -command => \&receive_json)->pack(-side => "bottom");
- my $clear_text = $right_frame->Button(-text => "Clear Text", -command => \&clear_entry)->pack(-anchor=>"ne");
- my $json_text = $right_frame->Text(-background => "white", -foreground => "black",-width=>"50",-height=>"20")->pack(-side => "top");
- sub clear_entry {
- $json_text->delete('0.0', 'end');
- }
- sub receive_json{
- my $json = $json_text->get('1.0','end'); #接收json数据
-
- my $url=$url_entry->get(); #接收post地址
- my $tx= $ua->post($url=>json=>$json);
- my $receive= $tx->res->body;
- $output_text->insert("end", $receive);
- }
- MainLoop;
复制代码 |
|