如何在RoR中编写此脚本

时间:2015-09-08 13:22:08

标签: bash ruby-on-rails-4 curl

如何通过ruby on rails编写此代码?

curl -k --cert path/cert.cer --key path/private.key -F "file=path/pkcs7.file" https://server.com/test > resp.txt 

更新 我使用了宝石遏制,我的解决方案:

http = Curl.post("https://server.com/test", signed_data) do|http|
  http.cert = "path/included_key.pem" # in linux: cat path/cert.cer path/private.key > path/included_key.pem, more info http://stackoverflow.com/questions/991758/how-to-get-an-openssl-pem-file-from-key-and-crt-files
  http.certpassword = '198512' # is optional
  http.headers["Content-Type"] = 'application/pkcs7-mime' # is optional, needs for me
  http.ssl_verify_peer = false # is equal -k flag in curl
end
Rails.logger.info http.body_str

1 个答案:

答案 0 :(得分:1)

解决方案

#include <iostream>
using namespace std;

#if 0
template <class F1, class F2>
struct overload : F1, F2 {
  overload(F1 f1, F2 f2) : F1(f1), F2(f2) { }

  using F1::operator();
  using F2::operator();
};

template <class F1, class F2>
auto make_overload(F1 f1, F2 f2) {
  return overload<F1, F2>(f1, f2);
}
#else
template <class... Fs>
struct overload;

template <class F0, class... Frest>
struct overload<F0, Frest...> : F0, overload<Frest...> {
  overload(F0 f0, Frest... rest) : F0(f0), overload<Frest...>(rest...) {}

  using F0::operator();
};

template <>
struct overload<> {
  overload() {}
};

template <class... Fs>
auto make_overload(Fs... fs) {
  return overload<Fs...>(fs...);
}
#endif

#if 0
#define CAP
#define PRINTY()
#else
#define CAP y
#define PRINTY() cout << "int y==" << y << endl
#endif

int main(int argc, char *argv[]) {
    int y = 123;

    auto f = make_overload(
        [CAP] (int x) { cout << "int x==" << x << endl; PRINTY(); },
        [CAP] (char *cp) { cout << "char *cp==" << cp << endl; PRINTY(); });
    f(argc);
    f(argv[0]);
}