简体   繁体   English

如何在rspec测试文件中转换curl请求

[英]How to convert the curl request in rspec test file

How do I convert the following CURL POST request to rspec controller test file. 如何将以下CURL POST请求转换为rspec控制器测试文件。

The controller#method I test is remote_test#upload 我测试的控制器#方法是remote_test#upload

curl -X POST -F report=@readme.md  
-H "X-User-Email: poc.hsu" -H "X-User-Token: WKyi9yAtquCn" 
-H 'X-Test-Token: bpBJHA' 
http://localhost:3000/remote_test/upload

I think that you must do something like: 我认为您必须执行以下操作:

post "path/to/route", {}, {'HTTP_ACCEPT' => "*/*", 'X-User-Token' => 'user_token_example', 'X-Test-Token' => 'bpBJHA'}

The second parameter is the optional parameters that you could pass to post or get methods. 第二个参数是可以传递给post或get方法的可选参数。

Best regards! 最好的祝福!

ruby has system method to execute os commands such as ls , cd etc. Of course including curl . ruby有执行os命令的系统方法,例如lscd等。当然包括curl (if the os can have the commnads) (如果操作系统可以包含命令)

system('curl http://www.yahoo.com')
# => return www.yahoo.com html ...

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

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