Fetching a URL without C Extensions/Libraries

2019-09-09 02:37发布

I'm working within the context of RPG Maker VX Ace. It has some Ruby extensions, and it has a subset of the Ruby 1.8 library built in. It also allows me to add my own .rb files -- such as the Ruby 1.9.3 source files -- albeit that I cannot use any code that has C extensions. If it requires a .so file, it won't work -- I'll get an error that "this application cannot load extensions/plugins."

Having understood this, I need some way to make an HTTP request. What I mean is:

I have tried using open-uri and net/http. Both of them have different issues that prevent me from using. One (I think it's the latter) requires TcpSocket, which is implemented in C and is not "pure" Ruby. The other one gives me an error about an undefined constant related to sockets.

I've also tried using the Socket class, and it gives me a similar error.

TLDR: Is there some way I can make a Ruby HTTP call with pure Ruby, no C extensions? That is what I need.

标签: ruby
2条回答
成全新的幸福
2楼-- · 2019-09-09 03:22

I solved this by writing some code and calling it from Ruby. Easy breezy.

Using .NET, I created a non-command-line, non-service application; something which I can invoke like a command-line app, but without the command-line window. To do this:

  • Create a new command-line project
  • Go to project properties
  • Change the type to "Windows Forms Application"

When you run your project, it'll run like any command-line project (args, etc.) but no windows will appear.

From there, it was easy to make an asynchronous HTTP request and store the response in a text file. This is sufficient for now.

查看更多
三岁会撩人
3楼-- · 2019-09-09 03:24

You could call out to a shell and execute curl (depending on your environment and the speed you want)

result = `curl "http://myserver.com/blah?data=abcd" -s`

The -s makes curl silent. See if that stops the dos box coming up.

查看更多
登录 后发表回答