2

I have a ruby script, that posts data to a URL:

require 'httparty'

data = {}
data[:client_id]     = '123123'
data[:key]           = '123321'

url = "http://someserver.com/endpoint/"
response = HTTParty.post(url, :body => data)

Now i am using Charles for sniffing the HTTP traffic. This works great from the browser, but not from the terminal, where I run my script:

$ ruby MyScript.rb

How can I tell ruby or my Terminal.app to use the Charles proxy at http://localhost:88888

Update Another solution would be to see the request before it is being sent. So that I would not necessarily need the proxy.

5
  • export http_proxy=localhost:88888 Commented Mar 6, 2014 at 21:57
  • @Timmah Even tough this might work, I tried this but I don't see any traffic in Charles when I do that. Commented Mar 6, 2014 at 22:02
  • so u tried export http_proxy=localhost:88888 && ruby MyScript.rb? Commented Mar 6, 2014 at 22:03
  • Call HTTParty::Basement.debug_output before your request and HTTParty will print debug messages, including raw request and response Commented Mar 6, 2014 at 23:09
  • The port 88888 is wrong. they can't be more than 65535, maybe is 8888. Also export http_proxy='http://localhost:8888' is the right syntax Commented Mar 7, 2014 at 23:00

1 Answer 1

2

Setting the proxy as timmah suggested should work.

Anyway 88888 is not a valid port! I think you want to use 8888 (Charles proxy default port).

So the right commands would be:

export http_proxy=localhost:8888
ruby MyScript.rb

If your script was to use https:// you would also/instead need to specify a HTTPS proxy like so:

export https_proxy=localhost:8888
Sign up to request clarification or add additional context in comments.

1 Comment

Connect to localhost.charlesproxy.com instead. That's the official way to do it. charlesproxy.com/documentation/faqs/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.