Forum: Ruby Net::HTTP#post_form - setting user agent, referrer?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
429500a5a54600958c9c7ac032a37f66?d=identicon&s=25 Joe (Guest)
on 2006-03-30 05:18
How can I set the user-agent and HTTP_REFERER (and perhaps other vars)
when using Net::HTTP's post_form method?

Thanks,
Joe
5892288702862ce1bf3fe2ae54745e72?d=identicon&s=25 Marc Soda (Guest)
on 2006-03-30 05:30
(Received via mailing list)
You can't.  Use HTTP#request_post(path, data, headers) where headers is
a hash.

Marc
429500a5a54600958c9c7ac032a37f66?d=identicon&s=25 Joe (Guest)
on 2006-03-31 04:55
Thanks. Anybody know how the headers are specified? I can't find any
documentation that spells it out. Is it...

headers = {
  'Referer' => 'http://xyz.com',
  'User-Agent' => 'mozillia'
}

Or...

headers = {
  'HTTP_REFERER' => 'http://xyz.com',
  'HTTP_USER_AGENT' => 'mozillia'
}


Thanks,
Joe
Cd2382441bbe2ec68e3bf36aea0ca2ea?d=identicon&s=25 Adam Keys (Guest)
on 2006-03-31 18:41
(Received via mailing list)
On Mar 30, 2006, at 8:55 PM, Joe wrote:
> Thanks. Anybody know how the headers are specified? I can't find any
> documentation that spells it out. Is it...
>
> headers = {
>   'Referer' => 'http://xyz.com',
>   'User-Agent' => 'mozillia'
> }
>

I believe this is the standard form.
Db802d5fad77c1e4f9c14bef9b87865c?d=identicon&s=25 Asit Katiyar (asitk)
on 2007-09-21 15:03
Adam Keys wrote:
> On Mar 30, 2006, at 8:55 PM, Joe wrote:
>> Thanks. Anybody know how the headers are specified? I can't find any
>> documentation that spells it out. Is it...
>>
>> headers = {
>>   'Referer' => 'http://xyz.com',
>>   'User-Agent' => 'mozillia'
>> }
>>
>
> I believe this is the standard form.

Hi,
I am also facing the same kind of problem. I tried with the solution
given in this thread, but couldn't succeeded.
When I try this:

response = NET::HTTP.request_post(url,post_args, headers)

I get the error:

undefined method `request_post' for Net::HTTP:Class

and when I try:

response = http.request_post(url,post_args, headers)

the error was:

undefined local variable or method `http' for Yahoo:Class

Please help me

Thanks
97550977337c9f0a0e1a9553e55bfaa0?d=identicon&s=25 Jano Svitok (Guest)
on 2007-09-21 15:35
(Received via mailing list)
On 9/21/07, Asit Katiyar <asitkatiyar@yahoo.com> wrote:
>
> and when I try:
>
> response = http.request_post(url,post_args, headers)
>
> the error was:
>
> undefined local variable or method `http' for Yahoo:Class

You're mixing class and instance methods. Either use HTTP.post_form()
or create an instance of HTTP with HTTP.new or HTTP.start and then use
http.post or http.post_request.

Jano
This topic is locked and can not be replied to.