免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1759 | 回复: 1
打印 上一主题 下一主题

用TK写了个发送json的小工具 [复制链接]

论坛徽章:
6
卯兔
日期:2013-11-26 14:52:02丑牛
日期:2014-02-19 18:01:25卯兔
日期:2014-05-20 20:34:06白羊座
日期:2014-05-23 13:39:232015亚冠之大阪钢巴
日期:2015-08-07 20:57:582015亚冠之大阪钢巴
日期:2015-09-02 14:09:09
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2013-04-27 18:34 |只看该作者 |倒序浏览
本帖最后由 只是一个红薯 于 2013-04-27 18:37 编辑

现遇到一个问题,从多行文本Text()读取的json数据接收后不知道是什么格式
接口取不到参数,代码如下:
  1. use 5.016;
  2. use strict;
  3. use autodie;
  4. use Mojo::UserAgent;
  5. use Tk;
  6. my $ua = Mojo::UserAgent->new;
  7. my $mw=MainWindow->new;
  8. $mw->geometry("800x600");
  9. my $main_frame = $mw->Frame(-background => "white")->pack(-side => 'top', -fill => 'x');

  10. my $left_frame = $main_frame->Frame(-background => "white")->pack(-anchor=>"nw", -ipadx=>"35");
  11. my $right_frame = $main_frame->Frame(-background => "white")->pack(-anchor=>"ne");
  12. my $bottom_frame= $main_frame->Frame(-background=>"white",-width=>"5")->pack(-side=>"bottom",-fill=>'x');
  13. $bottom_frame->Label(-text=>"output:",-background=>"white")->pack(-side=>"left");
  14. my $output_text=$bottom_frame->Text(-background => "white", -foreground => "black")->pack(-side => "bottom");

  15. $left_frame->Label(-text => "Url", -background => "white", -foreground => "black")->pack(-side => "left");
  16. $right_frame->Label(-text => "input_json", -background => "white", -foreground => "black")->pack(-side => "left");

  17. my $url_entry = $left_frame->Entry(-background => "white", -foreground => "red",-width=>"70")->pack(-side => "left");
  18. my $post_button = $left_frame->Button(-text => "post", -command => \&receive_json)->pack(-side => "bottom");
  19. my $clear_text = $right_frame->Button(-text => "Clear Text", -command => \&clear_entry)->pack(-anchor=>"ne");
  20. my $json_text = $right_frame->Text(-background => "white", -foreground => "black",-width=>"50",-height=>"20")->pack(-side => "top");
  21. sub clear_entry {
  22.     $json_text->delete('0.0', 'end');
  23.     }

  24. sub receive_json{
  25.     my $json = $json_text->get('1.0','end'); #接收json数据
  26.   
  27.     my $url=$url_entry->get(); #接收post地址
  28.     my $tx= $ua->post($url=>json=>$json);

  29.     my $receive= $tx->res->body;
  30.     $output_text->insert("end", $receive);
  31. }
  32. MainLoop;
复制代码
sinian126 该用户已被删除
2 [报告]
发表于 2013-04-28 08:47 |只看该作者
提示: 作者被禁止或删除 内容自动屏蔽
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP