Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WEBrick::HTTPStatus::LengthRequired with Twilio

Following the tutorial for Twilio Client. Got stuck here where you do the testing https://www.twilio.com/docs/quickstart/ruby/client/incoming-calls

curl -X POST http://localhost:3000/voice

I keep getting the WEBrick::HTTPStatus::LengthRequired response.

When I put it as

curl -X POST http://localhost:3000/voice -d ''

It works. But how do I fix for this in my routes or controller?

routes.rb

post 'voice', to: 'calls#voice', as: :voice

controller

def voice
    response = Twilio::TwiML::Response.new do |r|
    # Should be your Twilio Number or a verified Caller ID
        r.Dial :callerId => '+16479316790' do |d|
            d.Client 'jenny'
        end
    end
    render :text => response.text
end

Thanks! Also, if you have done this previously... having trouble adding localhost:3000 as the callback url in the dashboard. Any suggestions?

like image 307
Mohamed El Mahallawy Avatar asked Dec 04 '25 10:12

Mohamed El Mahallawy


1 Answers

The voice URL does not need to be a POST request, it can be a GET request. In the App dashboard, you can change the type of the voice request URL to GET and then modify your routes.rb to use get.

Using 'localhost' as the domain will not work as want a URL to point to your webserver. What you instead want is the full URL to your web server which you can accomplish with something like ngrok.

like image 200
Kunal Avatar answered Dec 06 '25 23:12

Kunal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!