HTTP post to a differnt port + no content type response

Discussion in 'Ruby' started by Alejandro Ramierz, Jan 8, 2007.

  1. Hello everyone, I'm trying my first ruby script here. What I am trying
    to do is sending an SMS using Kannel, for this Kannel runs an script in
    an specific port(13013).

    Basically you do a HTTP post like this:
    http://192.168.10.204:13013/cgi-bin...=444&to=44440295&smsc=mysmsc&text=hello world

    and i get an SMS in my mobile.


    I'm trying the following:

    #!/usr/bin/ruby
    require 'net/http'
    require 'uri'
    res =
    Net::HTTP.post_form(URI.parse('http://192.168.10.204:13013/cgi-bin/sendsms'),
    { 'user'=>'tester',
    'pass'=>'foobar',
    'from'=>'444',
    'to'=>'44440295',
    'smsc'=>'mysmsc',
    'text'=>'Test from ruby!'
    })
    puts res.body

    But i get the following Error:
    "Invalid content-type"

    I have also tried without the puts res.body part as the response from
    Kannel is a plain text response.


    I am thinking that the error is that I am trying to post in the port
    13013?

    Can someone please guide me on how to achieve this?



    Thank you



    alejandro

    --
    Posted via http://www.ruby-forum.com/.
     
    Alejandro Ramierz, Jan 8, 2007
    #1
    1. Advertising

  2. Alejandro Ramierz

    Jan Svitok Guest

    On 1/8/07, Alejandro Ramierz <> wrote:
    > Hello everyone, I'm trying my first ruby script here. What I am trying
    > to do is sending an SMS using Kannel, for this Kannel runs an script in
    > an specific port(13013).
    >
    > Basically you do a HTTP post like this:
    > http://192.168.10.204:13013/cgi-bin...=444&to=44440295&smsc=mysmsc&text=hello world
    >
    > and i get an SMS in my mobile.
    >
    >
    > I'm trying the following:
    >
    > #!/usr/bin/ruby
    > require 'net/http'
    > require 'uri'
    > res =
    > Net::HTTP.post_form(URI.parse('http://192.168.10.204:13013/cgi-bin/sendsms'),
    > { 'user'=>'tester',
    > 'pass'=>'foobar',
    > 'from'=>'444',
    > 'to'=>'44440295',
    > 'smsc'=>'mysmsc',
    > 'text'=>'Test from ruby!'
    > })
    > puts res.body
    >
    > But i get the following Error:
    > "Invalid content-type"
    >
    > I have also tried without the puts res.body part as the response from
    > Kannel is a plain text response.
    >
    >
    > I am thinking that the error is that I am trying to post in the port
    > 13013?
    >
    > Can someone please guide me on how to achieve this?


    Hi,

    different port should not be a prolem. I think your problem is that
    you are trying to use POST method (HTTP.post_form) while what you
    really want is GET (at least your first example implies that).

    So try

    #!/usr/bin/ruby
    require 'net/http'
    require 'uri'

    uri = URI.parse('http://192.168.10.204:13013/cgi-bin/sendsms')
    uri.set_query( 'user'=>'tester', 'pass'=>'foobar', 'from'=>'444',
    'to'=>'44440295', 'smsc'=>'mysmsc', 'text'=>'Test from ruby!')

    res = Net::HTTP.get(uri),
    puts res.body

    I have not tested this, so maybe you'll need to fix this.
     
    Jan Svitok, Jan 8, 2007
    #2
    1. Advertising

  3. Jan Svitok wrote:
    > On 1/8/07, Alejandro Ramierz <> wrote:
    >> I'm trying the following:
    >> 'smsc'=>'mysmsc',
    >>
    >> I am thinking that the error is that I am trying to post in the port
    >> 13013?
    >>
    >> Can someone please guide me on how to achieve this?

    >
    > Hi,
    >
    > different port should not be a prolem. I think your problem is that
    > you are trying to use POST method (HTTP.post_form) while what you
    > really want is GET (at least your first example implies that).
    >
    > So try
    >
    > #!/usr/bin/ruby
    > require 'net/http'
    > require 'uri'
    >
    > uri = URI.parse('http://192.168.10.204:13013/cgi-bin/sendsms')
    > uri.set_query( 'user'=>'tester', 'pass'=>'foobar', 'from'=>'444',
    > 'to'=>'44440295', 'smsc'=>'mysmsc', 'text'=>'Test from ruby!')
    >
    > res = Net::HTTP.get(uri),
    > puts res.body
    >


    Or

    #!/usr/bin/ruby
    require 'open-uri'
    p
    open("http://192.168.10.204:13013/cgi-bin/sendsms?user=tester&pass=foobar&from=444&to=3423424&smsc=mysmsc&text=test
    from ruby")


    -.rb


    --
    Posted via http://www.ruby-forum.com/.
     
    Rodrigo Bermejo, Jan 8, 2007
    #3
  4. Thank you Jan and Rodrigo for taking the time to answer!

    I've tried Rodrigo's version and it worked fine! But i am curious as of
    the error i get from Jan's version:

    protected method `set_query' called for #<URI::HTTP:0xb7f6ed90>
    (NoMethodError)

    I have looked of the set_query Method but there is not much info there.
    What could be the cause of this?


    again thanks!


    Alejandro


    Rodrigo Bermejo wrote:
    > Jan Svitok wrote:
    >> On 1/8/07, Alejandro Ramierz <> wrote:
    >>> I'm trying the following:
    >>> 'smsc'=>'mysmsc',
    >>>
    >>> I am thinking that the error is that I am trying to post in the port
    >>> 13013?
    >>>
    >>> Can someone please guide me on how to achieve this?

    >>
    >> Hi,
    >>
    >> different port should not be a prolem. I think your problem is that
    >> you are trying to use POST method (HTTP.post_form) while what you
    >> really want is GET (at least your first example implies that).
    >>
    >> So try
    >>
    >> #!/usr/bin/ruby
    >> require 'net/http'
    >> require 'uri'
    >>
    >> uri = URI.parse('http://192.168.10.204:13013/cgi-bin/sendsms')
    >> uri.set_query( 'user'=>'tester', 'pass'=>'foobar', 'from'=>'444',
    >> 'to'=>'44440295', 'smsc'=>'mysmsc', 'text'=>'Test from ruby!')
    >>
    >> res = Net::HTTP.get(uri),
    >> puts res.body
    >>

    >
    > Or
    >
    > #!/usr/bin/ruby
    > require 'open-uri'
    > p
    > open("http://192.168.10.204:13013/cgi-bin/sendsms?user=tester&pass=foobar&from=444&to=3423424&smsc=mysmsc&text=test
    > from ruby")
    >
    >
    > -.rb



    --
    Posted via http://www.ruby-forum.com/.
     
    Alejandro Ramirez, Jan 9, 2007
    #4
  5. Alejandro Ramierz

    Jan Svitok Guest

    On 1/9/07, Alejandro Ramirez <> wrote:
    > Thank you Jan and Rodrigo for taking the time to answer!
    >
    > I've tried Rodrigo's version and it worked fine! But i am curious as of
    > the error i get from Jan's version:
    >
    > protected method `set_query' called for #<URI::HTTP:0xb7f6ed90>
    > (NoMethodError)
    >
    > I have looked of the set_query Method but there is not much info there.
    > What could be the cause of this?


    I see... as I said, I haven't tried the code myself. Maybe try just
    uri.query=, although I don't know what format it takes. Try either
    hash or string. Or look it up in the sources ;-)
     
    Jan Svitok, Jan 9, 2007
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Galsaba
    Replies:
    6
    Views:
    364
    Galsaba
    Apr 17, 2004
  2. =?Utf-8?B?QWxwaGFRdXAybml0ZQ==?=

    How to allow access to HD that was used with a differnt computer

    =?Utf-8?B?QWxwaGFRdXAybml0ZQ==?=, Nov 3, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    367
    =?Utf-8?B?TGVvbiBNYXluZQ==?=
    Nov 6, 2006
  3. Tamer Ibrahim
    Replies:
    1
    Views:
    586
    JIGNESH
    Jan 17, 2008
  4. merfh3
    Replies:
    0
    Views:
    262
    merfh3
    Feb 1, 2011
  5. Jo

    a differnt way to consuming web services?

    Jo, Apr 26, 2006, in forum: ASP .Net Web Services
    Replies:
    14
    Views:
    423
Loading...

Share This Page