大多数程序员都喜欢偷懒的,我也不例外.相信好多Android开发的coder 在网络http请求方面,会浪费很多时间在接口调试这里..有时候,自己写了一个小测试,行还好,不行的话,还要跟写后台的哥们一起扯扯蛋...于是自己就写了一个curl的小脚本,专门调试这方面的东西.(主要适用于用JSON的传输方式).

   废话不多说,直接看我的SHELL吧:

  

#!/bin/sh
echo -n "enter the request host: "
read host # request host #cookie
echo -n "use cookie ? (y/n) "
read is_cookie cookie="" #if need cookie set
if [[ $is_cookie = "y" ]]; then
echo -n "input the cookie: "
read input_cookie
cookie=$input_cookie
fi echo -n "need post? (y/n) "
read tag #http get if tag = n
if [[ $tag = "n" ]]; then
if [[ $cookie != "" ]]; then
curl $host -b$cookie
else
curl $host
fi
exit 0
fi #the json data need to post
data="" #the input value pair
kv_pair="" while true; do
if [[ $tag = "y" ]]; then
#input key
echo -n "key : "
read key # set break condition key = gameover 这里是一个循环结束的标志.输入这个标志表示我需要传递的json数据已经全部写进去了
if [[ $key = "gameover" ]]; then
#complete the json format, %,* start at right side and romove the first ','
kv_pair=${kv_pair%,*} #this is the last data to post
data="{"$kv_pair"}"
echo "post data is: $data and exce the curl cmd"
#curl $host -d$data
break;
fi #encode with ""
key='"'$key'"' #input value
echo -n "value : "
read value #encode value with ""
value='"'$value'"' #set value pair and extends itself
kv_pair="$kv_pair"$key":"$value","
echo "$kv_pair"
fi done #do http post
if [[ $cookie != "" ]]; then
curl $host -d$data -b$cookie
else
curl $host -d$data
fi

  我的是在mac os 下运行的,输入命令 bash xx.sh (xx是你的文件名) .就可以运行了,运行效果如下:

下面是我的一个登录的接口调试.

输入的JSON只需要对着key value输入就好了..gameover的时候就有结果了..有点方便吧..这个东西能跑通,说明后台接口基本能运行~~然后你就专心写你的请求代码吧..

第一个Shell脚本到此结束...新手写得比较菜..有不妥地方大家多拍砖..

第一个Mac shell 小脚本的更多相关文章

  1. Mac shell 小脚本开发(转)

    大多数程序员都喜欢偷懒的,我也不例外.相信好多Android开发的coder 在网络http请求方面,会浪费很多时间在接口调试这里..有时候,自己写了一个小测试,行还好,不行的话,还要跟写后台的哥们一 ...

  2. 一个Shell小脚本——旋转的斜杠

    话不多说,请从代码中寻找乐趣吧! #!/bin/bash #----中断计数器----# incr= #----旋转的斜杠----# spin="/-\|" echo -en &q ...

  3. Linux Shell 小脚本经典收藏

    原文:http://www.cnblogs.com/Javame/p/3867686.html 1.在两个文件中找出相同的号码 diff -y xx.txt oo.txt | egrep -v &qu ...

  4. shell小脚本--网速监控

    在windows中,我们可以在360等管家软件中显示网速,在linux下想要查看实时的网速怎么办呢?当然在linux下也有很多优秀的软件可以实时显示网络状况!但是在这里我们使用shell脚本来先完成网 ...

  5. python写一个翻译的小脚本

    起因: 想着上学看不懂English的PDF感慨万分........ 然后就有了翻译的脚本. 截图: 代码: #-*- coding:'utf-8' -*- import requests impor ...

  6. shell小脚本工具合集

    1.将指定内容写入文件 echo "hello world" > file.txt echo "hello world" >> file.tx ...

  7. shell小脚本--从laod博客更新hosts文件

    #!/bin/bash #-------------------------------------------- # name: change-hosts.sh #----------------- ...

  8. 汇总下几个IP计算/转换的shell小脚本-转

    原文:http://blog.chinaunix.net/uid-20788470-id-1841646.html   1. IP转换为整数> vi ip2num.sh#!/bin/bash# ...

  9. 6条shell小技巧,让脚本显得不再业余【转】

    如何能让自己的shell显得不那么业余?下面6点实践一定有用. 画外音:本篇文章源自Google的一篇实践,抽取了部分1分钟能读完的内容,加入了一些分析. 一.以下面的语句开场 set -o noun ...

随机推荐

  1. VS2015编译boost1.62

    VS2015编译boost1.62 Boost库是一个可移植.提供源代码的C++库,作为标准库的后备,是C++标准化进程的开发引擎之一. Boost库由C++标准委员会库工作组成员发起,其中有些内容有 ...

  2. linux回退到上次访问目录

    cd / cd ..  回到上级目录 cd - 回到上次访问目录

  3. redis lua

    需求是在缓存最近一周内用户所有消息列表,考虑用Redis 存储:为每个存储一个独立Sorted Set,value 为消息体,Score 为MessageId,用以实现增量消息同步. 问题就来了:So ...

  4. iOS coredata 数据库的加密(待研究)

    https://github.com/project-imas/encrypted-core-data 使用起来很方便,底层还是使用了SQLCipher,有时间要研究一下! 数据库的密码不能用固定字符 ...

  5. Mac系统下开启和关闭隐藏文件的方法

    在Mac下找到终端,输入以下命令(注意区分大小写): 显示Mac隐藏文件的命令: defaults write com.apple.finder AppleShowAllFiles -bool tru ...

  6. Shell 获取指定行的内容

    需求: 有一个文件,根据指定的字符串,得到该字符串上两行的内容. 文件内容如下: linux-56:# cat sys.ttconnect.ini # Copyright (C) 1999, 2006 ...

  7. EF多对多更新报错(TableNoTracking引发的bug)

    实体映射关系如下,SISTUser和SISTUserRoles存在多对多的关系,生成中间表 public partial class SISTUserMap: EntityTypeConfigurat ...

  8. CSS--实现小三角形

    <style> html, body { margin: 0; padding: 0; } /*下面用CSS3分别实现向上.下.左.右的三角形*/ .btn-color{ color: # ...

  9. oracle 11.2.0.4单实例文件系统安装与补丁

    [TOC] 一,预安装处理 1.版本准备 操作系统:RHEL 6.5 数据库版本:Oracle 11.2.0.4 相关包:p13390677_112040_Linux-x86-64_1of7.zip  ...

  10. webpack

    webpack 通过一个主文件 .js ,webpack把这个文件所有的依赖文件,都处理打包成js文件 webpack 可以干嘛?1.执行打包 (把require()模块化整合成一个js文件给html ...