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

J

Joe

How can I set the user-agent and HTTP_REFERER (and perhaps other vars)
when using Net::HTTP's post_form method?

Thanks,
Joe
 
M

Marc Soda

You can't. Use HTTP#request_post(path, data, headers) where headers is a h=
ash.

Marc
 
J

Joe

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
 
A

Asit Katiyar

Adam said:
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
 
J

Jano Svitok

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

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top