# HTTP post to a differnt port + no content type response

**URL:** <https://www.ruby-forum.com/t/http-post-to-a-differnt-port-no-content-type-response/81416>\
**Category:** Ruby\
**Created:** [January 8, 2007, 11:20pm UTC](https://www.ruby-forum.com/t/http-post-to-a-differnt-port-no-content-type-response/81416 "2007-01-08T23:20:46Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![alexr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/8dc957/32.png) [@alexr](https://www.ruby-forum.com/u/alexr)\
**Post date:** [January 8, 2007, 11:20pm UTC](https://www.ruby-forum.com/t/http-post-to-a-differnt-port-no-content-type-response/81416/1 "2007-01-08T23:20:46Z")

</div>

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/sendsms?username=tester&password=foobar&from=444&to=44440295&smsc=mysmsc&text=hello+world](http://192.168.10.204:13013/cgi-bin/sendsms?username=tester&password=foobar&from=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](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

---

<div class="post-metadata">

**Author:** ![alexr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/8dc957/32.png) [@alexr](https://www.ruby-forum.com/u/alexr)\
**Post date:** [January 9, 2007, 12:17am UTC](https://www.ruby-forum.com/t/http-post-to-a-differnt-port-no-content-type-response/81416/2 "2007-01-09T00:17:00Z")

</div>

On 1/8/07, Alejandro R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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](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.

---

<div class="post-metadata">

**Author:** ![alexr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/8dc957/32.png) [@alexr](https://www.ruby-forum.com/u/alexr)\
**Post date:** [January 9, 2007, 12:29am UTC](https://www.ruby-forum.com/t/http-post-to-a-differnt-port-no-content-type-response/81416/3 "2007-01-09T00:29:45Z")

</div>

Jan S. wrote:

> On 1/8/07, Alejandro R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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](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](http://192.168.10.204:13013/cgi-bin/sendsms?user=tester&pass=foobar&from=444&to=3423424&smsc=mysmsc&text=test)  
from ruby”)

-.rb

---

<div class="post-metadata">

**Author:** ![alexr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/8dc957/32.png) [@alexr](https://www.ruby-forum.com/u/alexr)\
**Post date:** [January 10, 2007, 12:24am UTC](https://www.ruby-forum.com/t/http-post-to-a-differnt-port-no-content-type-response/81416/4 "2007-01-10T00:24:02Z")

</div>

On 1/9/07, Alejandro R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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 😉

---

<div class="post-metadata">

**Author:** ![alexr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/8dc957/32.png) [@alexr](https://www.ruby-forum.com/u/alexr)\
**Post date:** [January 9, 2007, 6:06pm UTC](https://www.ruby-forum.com/t/http-post-to-a-differnt-port-no-content-type-response/81416/5 "2007-01-09T18:06:00Z")

</div>

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 B. wrote:

> Jan S. wrote:
> 
> > On 1/8/07, Alejandro R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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](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](http://192.168.10.204:13013/cgi-bin/sendsms?user=tester&pass=foobar&from=444&to=3423424&smsc=mysmsc&text=test)  
> from ruby”)
> 
> -.rb
