librelist archives

« back to archive

Using download() + http basic authorization

Using download() + http basic authorization

From:
Michel Belleville
Date:
2009-12-09 @ 09:08
Hi guys,
I'm trying to make a little app reading a webservice restricted through
basic http authorization. The problem is I can't find how to do it, I tried
putting the credentials in the url as I would using any browser's url input
(http://the_login:the_password@server.com/resource.xml) but to no avail (I
get a 401 : unauthorized, the webservice doesn't even get the credentials).

So, any idea how to do this ?

Michel Belleville

Re: Using download() + http basic authorization

From:
Michel Belleville
Date:
2009-12-09 @ 09:42
I've tried through Net::HTTP but I get this error message on shoes :
connection refused - connect(2)

The webservice hasn't even been reached (no trace of a query in the logs).

Though when I try the very same script and the very same data using standard
ruby console it connects and get the response without failing.

I tried to upgrade shoes to the latest MacOSX build (on github) but the same
problem persists.

Please has anyone got an idea that would lead me to the right tracks ?

Michel Belleville


2009/12/9 Michel Belleville <michel.belleville@gmail.com>

> Hi guys,
> I'm trying to make a little app reading a webservice restricted through
> basic http authorization. The problem is I can't find how to do it, I tried
> putting the credentials in the url as I would using any browser's url input
> (http://the_login:the_password@server.com/resource.xml) but to no avail (I
> get a 401 : unauthorized, the webservice doesn't even get the credentials).
>
> So, any idea how to do this ?
>
> Michel Belleville
>

Re: Using download() + http basic authorization

From:
Saurabh Bhatia
Date:
2009-12-09 @ 09:50
Maybe you require a webservice wrapper, in case of soap use soap4r, i am
assuming you are using some webservice whose native support is inbuilt in
ruby like wsdl. You need to include like in this,
http://ruby-doc.org/stdlib/libdoc/wsdl/rdoc/index.html

I think thats the problem

On Wed, Dec 9, 2009 at 3:12 PM, Michel Belleville <
michel.belleville@gmail.com> wrote:

> I've tried through Net::HTTP but I get this error message on shoes :
> connection refused - connect(2)
>
> The webservice hasn't even been reached (no trace of a query in the logs).
>
> Though when I try the very same script and the very same data using
> standard ruby console it connects and get the response without failing.
>
> I tried to upgrade shoes to the latest MacOSX build (on github) but the
> same problem persists.
>
> Please has anyone got an idea that would lead me to the right tracks ?
>
> Michel Belleville
>
>
> 2009/12/9 Michel Belleville <michel.belleville@gmail.com>
>
> Hi guys,
>> I'm trying to make a little app reading a webservice restricted through
>> basic http authorization. The problem is I can't find how to do it, I tried
>> putting the credentials in the url as I would using any browser's url input
>> (http://the_login:the_password@server.com/resource.xml) but to no avail
>> (I get a 401 : unauthorized, the webservice doesn't even get the
>> credentials).
>>
>> So, any idea how to do this ?
>>
>> Michel Belleville
>>
>
>


-- 
Best Regards

Saurabh Bhatia

http://safewlabs.com/
http://github.com/saurabhbhatia

Re: Using download() + http basic authorization

From:
Michel Belleville
Date:
2009-12-09 @ 09:59
Well thanks for answering ; if the webservice was using soap that could be
the case, but actually it's just a basic rails site with routes that maps to
xml rendered files and authenticates users through the very plain basic http
authentication standard (the one that pops a login / password modal window
when you try to reach it through a browser), and anyway either download() or
net::http doesn't even seem to reach the webservice using shoes (no traces
of queries in the log) whereas the net::http used in console gets reaches
the webservice and gets authenticated a treat.

So, any other idea ?

Michel Belleville


2009/12/9 Saurabh Bhatia <saurabh.a.bhatia@gmail.com>

> Maybe you require a webservice wrapper, in case of soap use soap4r, i am
> assuming you are using some webservice whose native support is inbuilt in
> ruby like wsdl. You need to include like in this,
> http://ruby-doc.org/stdlib/libdoc/wsdl/rdoc/index.html
>
> I think thats the problem
>
>
> On Wed, Dec 9, 2009 at 3:12 PM, Michel Belleville <
> michel.belleville@gmail.com> wrote:
>
>> I've tried through Net::HTTP but I get this error message on shoes :
>> connection refused - connect(2)
>>
>> The webservice hasn't even been reached (no trace of a query in the logs).
>>
>> Though when I try the very same script and the very same data using
>> standard ruby console it connects and get the response without failing.
>>
>> I tried to upgrade shoes to the latest MacOSX build (on github) but the
>> same problem persists.
>>
>> Please has anyone got an idea that would lead me to the right tracks ?
>>
>> Michel Belleville
>>
>>
>> 2009/12/9 Michel Belleville <michel.belleville@gmail.com>
>>
>>  Hi guys,
>>> I'm trying to make a little app reading a webservice restricted through
>>> basic http authorization. The problem is I can't find how to do it, I tried
>>> putting the credentials in the url as I would using any browser's url input
>>> (http://the_login:the_password@server.com/resource.xml) but to no avail
>>> (I get a 401 : unauthorized, the webservice doesn't even get the
>>> credentials).
>>>
>>> So, any idea how to do this ?
>>>
>>> Michel Belleville
>>>
>>
>>
>
>
> --
> Best Regards
>
> Saurabh Bhatia
>
> http://safewlabs.com/
> http://github.com/saurabhbhatia
>
>
>
>

Re: Using download() + http basic authorization

From:
i5m
Date:
2009-12-09 @ 10:11
There might be some ideas in this thread:

http://thread.gmane.org/gmane.comp.lib.shoes/2455

<http://thread.gmane.org/gmane.comp.lib.shoes/2455>
-----------------------
i5m.co.uk
GPG Key: 0xA18A602B


On Wed, Dec 9, 2009 at 9:59 AM, Michel Belleville <
michel.belleville@gmail.com> wrote:

> Well thanks for answering ; if the webservice was using soap that could be
> the case, but actually it's just a basic rails site with routes that maps to
> xml rendered files and authenticates users through the very plain basic http
> authentication standard (the one that pops a login / password modal window
> when you try to reach it through a browser), and anyway either download() or
> net::http doesn't even seem to reach the webservice using shoes (no traces
> of queries in the log) whereas the net::http used in console gets reaches
> the webservice and gets authenticated a treat.
>
> So, any other idea ?
>
> Michel Belleville
>
>

Re: Using download() + http basic authorization

From:
Michel Belleville
Date:
2009-12-09 @ 10:16
Thanks a lot, I'm trying it right now.

Michel Belleville


2009/12/9 i5m <i5ivem@googlemail.com>

> There might be some ideas in this thread:
>
> http://thread.gmane.org/gmane.comp.lib.shoes/2455
>
> <http://thread.gmane.org/gmane.comp.lib.shoes/2455>
> -----------------------
> i5m.co.uk
> GPG Key: 0xA18A602B
>
>
>
> On Wed, Dec 9, 2009 at 9:59 AM, Michel Belleville <
> michel.belleville@gmail.com> wrote:
>
>> Well thanks for answering ; if the webservice was using soap that could be
>> the case, but actually it's just a basic rails site with routes that maps to
>> xml rendered files and authenticates users through the very plain basic http
>> authentication standard (the one that pops a login / password modal window
>> when you try to reach it through a browser), and anyway either download() or
>> net::http doesn't even seem to reach the webservice using shoes (no traces
>> of queries in the log) whereas the net::http used in console gets reaches
>> the webservice and gets authenticated a treat.
>>
>> So, any other idea ?
>>
>> Michel Belleville
>>
>>

Re: Using download() + http basic authorization

From:
Michel Belleville
Date:
2009-12-09 @ 10:30
Just walked through the entire thread and sadly it doesn't help, I've tried
all suggestions in with no positive result (the best I'm getting is 401
errors from download() using the :basic_auth parameter, or instant shoes
crashes I set the :header parameter with 'Authorisation' using base64
encoding).

Isn't there a way to work around this limitation or getting Net::HTTP or any
other library to actually send the query ? So far I've also tried HTTParty
which didn't work just as Net::HTTP doesn't seem to work ?

Michel Belleville


2009/12/9 Michel Belleville <michel.belleville@gmail.com>

> Thanks a lot, I'm trying it right now.
>
> Michel Belleville
>
>
> 2009/12/9 i5m <i5ivem@googlemail.com>
>
> There might be some ideas in this thread:
>>
>> http://thread.gmane.org/gmane.comp.lib.shoes/2455
>>
>> <http://thread.gmane.org/gmane.comp.lib.shoes/2455>
>> -----------------------
>> i5m.co.uk
>> GPG Key: 0xA18A602B
>>
>>
>>
>> On Wed, Dec 9, 2009 at 9:59 AM, Michel Belleville <
>> michel.belleville@gmail.com> wrote:
>>
>>> Well thanks for answering ; if the webservice was using soap that could
>>> be the case, but actually it's just a basic rails site with routes that maps
>>> to xml rendered files and authenticates users through the very plain basic
>>> http authentication standard (the one that pops a login / password modal
>>> window when you try to reach it through a browser), and anyway either
>>> download() or net::http doesn't even seem to reach the webservice using
>>> shoes (no traces of queries in the log) whereas the net::http used in
>>> console gets reaches the webservice and gets authenticated a treat.
>>>
>>> So, any other idea ?
>>>
>>> Michel Belleville
>>>
>>>
>

Re: Using download() + http basic authorization

From:
i5m
Date:
2009-12-09 @ 10:53
Michel,

I'm not on OSX right now so can't check this out. But as far as I know
Net:HTTP should work. The only thread I 've found where someone was having
problems was this thread:

http://thread.gmane.org/gmane.comp.lib.shoes/3312

<http://thread.gmane.org/gmane.comp.lib.shoes/3312>where it wasn't resolving
'localhost'

I've also seen (and experienced) problems on Windows with proxies, etc, but
not on OSX.

Any chance you could post a bit of code. details of the site? Obviously we
don't need acounts/passwords, but we could try to connect.

Kind regards,

i5m


-----------------------
i5m.co.uk
GPG Key: 0xA18A602B


On Wed, Dec 9, 2009 at 9:42 AM, Michel Belleville <
michel.belleville@gmail.com> wrote:

> I've tried through Net::HTTP but I get this error message on shoes :
> connection refused - connect(2)
>
> The webservice hasn't even been reached (no trace of a query in the logs).
>
> Though when I try the very same script and the very same data using
> standard ruby console it connects and get the response without failing.
>
> I tried to upgrade shoes to the latest MacOSX build (on github) but the
> same problem persists.
>
> Please has anyone got an idea that would lead me to the right tracks ?
>
> Michel Belleville
>
>
>
>

Re: Using download() + http basic authorization

From:
Michel Belleville
Date:
2009-12-09 @ 11:04
Localhost indeed. Thanks a whole big bunch, now it's working a treat.

As for the code, it's really straightforward but I guess some would be glad
to find something if they stumble upon this ml so :

require 'base64'
require 'net/http'
require 'uri'

Shoes.app {
  stack {
    @user_login    = edit_line :text => 'login'
    @user_password = edit_line :text => 'password'
    @method        = list_box  :items => ["GET", "POST", "PUT", "DELETE"]
    @url_base      = edit_line :text => 'http://127.0.0.1:3000/webservice'
    @url_resource  = edit_line :text => 'resource.xml'
    button("GO !") {
      url = URI.parse("#{@url_base.text}/#{@url_resource.text}")
      method = @method.text
      params = {}
      unless method == 'GET'
        params.merge!({ :_method => method }) unless method == 'POST'
        method = 'POST'
      end

      Net::HTTP.start(url.host, url.port) { |http|
        req = Net::HTTP::Get.new(url.path)
        req.basic_auth @user_login.text, @user_password.text
        response = http.request(req)
        debug response.body
      }
    }
  }
}

Thanks again.

Michel Belleville


2009/12/9 i5m <i5ivem@googlemail.com>

> Michel,
>
> I'm not on OSX right now so can't check this out. But as far as I know
> Net:HTTP should work. The only thread I 've found where someone was having
> problems was this thread:
>
> http://thread.gmane.org/gmane.comp.lib.shoes/3312
>
> <http://thread.gmane.org/gmane.comp.lib.shoes/3312>where it wasn't
> resolving 'localhost'
>
> I've also seen (and experienced) problems on Windows with proxies, etc, but
> not on OSX.
>
> Any chance you could post a bit of code. details of the site? Obviously we
> don't need acounts/passwords, but we could try to connect.
>
> Kind regards,
>
> i5m
>
>
> -----------------------
> i5m.co.uk
> GPG Key: 0xA18A602B
>
>
> On Wed, Dec 9, 2009 at 9:42 AM, Michel Belleville <
> michel.belleville@gmail.com> wrote:
>
>> I've tried through Net::HTTP but I get this error message on shoes :
>> connection refused - connect(2)
>>
>> The webservice hasn't even been reached (no trace of a query in the logs).
>>
>> Though when I try the very same script and the very same data using
>> standard ruby console it connects and get the response without failing.
>>
>> I tried to upgrade shoes to the latest MacOSX build (on github) but the
>> same problem persists.
>>
>> Please has anyone got an idea that would lead me to the right tracks ?
>>
>> Michel Belleville
>>
>>
>>
>>