繁体   English   中英

使用 tsung POST 请求发送 json

[英]Sending json with tsung POST request

我正在尝试使用 Tsung 创建一个 POST 请求

<request> 
  <http url="api.whatever.com" method="POST" version="1.1" contents=""></http>
</request>

如何在内容属性中发送 JSON 文档?

contents='{"name": "alex"}' 

当然是无效的...

有没有办法可以通过我的 POST 请求发送 JSON?

我可以通过替换" &quot;并添加内容类型标题 application/json 来做到这一点

所以我的例子会变成:

content_type='application/json' contents='{&quot;name&quot;: &quot;alex&quot;}

最简单的方法(从 Tsung 1.3 开始)是使用contents_from_file属性。 这避免了大量转义数据污染您的代码,并使您能够获取任何原始数据并将其转储到您选择的文件中

<http url="mypage" 
      method="POST" 
      content_type='application/json'
      contents_from_file="/tmp/myfile.json" 
/>

发送json时,我一般是在Wireshark中捕获一些成功的请求,而没有运行tsung。

然后我找到其中一个数据包的 IP 地址,选择“分析”菜单并选择“遵循 TCP 流”。

这使我可以看到发送的实际数据。

数据可能如下所示:

data.text=US+intelligence+agents+have+been+hacking+computer+networks%0A++++++++++++++++++++++++around+the+world+for+years%2C+apparently+targeting+fat+data%0A++++++++++++++++++++++++pipes+that+push+immense+amounts+of+data+around+the+Internet%2C%0A++++++++++++++++++++++++NSA+leaker+Edward+Snowden+t&amp;type=text&amp;data.sender-id=8a5b1c2f-0589-464c-82c4-b8f4e280511a'

然后我将 tsung xml 修改为:

content_type='application/x-www-form-urlencoded' contents=''

并将数据粘贴到内容中。

您也可以尝试使用 " 转义引号,但我从来没有运气。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM