http-access2 POSTing

  • Thread starter Andi Scharfstein
  • Start date
A

Andi Scharfstein

Hi,
I've been expecting a certain eMail for some time now, and I have never
been good with waiting for mail. So, in order to have something to do to
distract me from waiting, I decided to write a script that would forward
the mail to my cellphone using SMS. I am using a German FreeSMS provider
(http://www.myskoda.de) which doesn't expressly forbid automated use of
its services, so it's kind of legal ;)
So, after creating an account there, I tried writing my script, but it
doesn't do what I want it to... I expect this is a result of my lack of
understanding of HTTP messages. I am using http-access2 to access a form
on the FreeSMS site that has the following structure:

<FORM action="/emailsys/sms/sms.html" method="post" name="SendMessage">
<SELECT name=network>
<OPTION selected value="151">+49 151</OPTION>
<OPTION value="160">+49 160</OPTION>
</SELECT>
<INPUT class=ftext maxLength=8 name=number size=20>
<TEXTAREA cols=40 name=msg ></TEXTAREA>
<INPUT TYPE="IMAGE" NAME="send_sms" SRC="../images/opt-hinzu.gif">
</FORM>

After logging in [client.get('http://www.myskoda.de/index.html',
{"callname" => "mylogin", "password" => "mypass"})], which works as
expected, I try to do the following:
client.post('http://www.myskoda.de/emailsys/sms/sms.html', {"network" =>
"151", "number" => "12345678", "msg" => text})
where text is a string that does not exceed 147 chars (that's 160 chars
maximum in a SMS message minus the MySkoda ad). This doesn't work: All I
get is the same site again (which is OK, it's the same URL), but it
should say "Message sent, now 4 messages left [for this month]", which it
doesn't. Yes, I know that's a kind of unusual question. Any ideas?
 
A

Ara.T.Howard

Hi, I've been expecting a certain eMail for some time now, and I have never
been good with waiting for mail. So, in order to have something to do to
distract me from waiting, I decided to write a script that would forward the
mail to my cellphone using SMS. I am using a German FreeSMS provider
(http://www.myskoda.de) which doesn't expressly forbid automated use of its
services, so it's kind of legal ;) So, after creating an account there, I
tried writing my script, but it doesn't do what I want it to... I expect
this is a result of my lack of understanding of HTTP messages. I am using
http-access2 to access a form on the FreeSMS site that has the following
structure:

<FORM action="/emailsys/sms/sms.html" method="post" name="SendMessage">
<SELECT name=network>
<OPTION selected value="151">+49 151</OPTION>
<OPTION value="160">+49 160</OPTION>
</SELECT>
<INPUT class=ftext maxLength=8 name=number size=20>
<TEXTAREA cols=40 name=msg ></TEXTAREA>
<INPUT TYPE="IMAGE" NAME="send_sms" SRC="../images/opt-hinzu.gif">
</FORM>

After logging in [client.get('http://www.myskoda.de/index.html', {"callname"
=> "mylogin", "password" => "mypass"})], which works as expected,

so sending the authentication this way works.
I try to do the following:
client.post('http://www.myskoda.de/emailsys/sms/sms.html', {"network" =>
"151", "number" => "12345678", "msg" => text})

i don't know this api - but is the autentication information sent
(automatically) again here? typically browsers do this for once you've done
it once, but i don't know if this object does that or not?
where text is a string that does not exceed 147 chars (that's 160 chars
maximum in a SMS message minus the MySkoda ad). This doesn't work: All I get
is the same site again (which is OK, it's the same URL), but it should say
"Message sent, now 4 messages left [for this month]", which it doesn't. Yes,
I know that's a kind of unusual question. Any ideas?

====================================
| Ara Howard
| NOAA Forecast Systems Laboratory
| Information and Technology Services
| Data Systems Group
| R/FST 325 Broadway
| Boulder, CO 80305-3328
| Email: (e-mail address removed)
| Phone: 303-497-7238
| Fax: 303-497-7259
| The difference between art and science is that science is what we understand
| well enough to explain to a computer. Art is everything else.
| -- Donald Knuth, "Discover"
| ~ > /bin/sh -c 'for lang in ruby perl; do $lang -e "print \"\x3a\x2d\x29\x0a\""; done'
====================================
 
N

NAKAMURA, Hiroshi

Hi,
From: "Andi Scharfstein" <[email protected]>
Sent: Thursday, October 02, 2003 8:05 PM

I know nothing about this site but if the site use HTTP-Cookies,

client.set_cookie_store("cookie.dat")

before
After logging in [client.get('http://www.myskoda.de/index.html',
{"callname" => "mylogin", "password" => "mypass"})]
and

client.post('http://www.myskoda.de/emailsys/sms/sms.html', {"network" =>
"151", "number" => "12345678", "msg" => text})

might help.

# Bear in mind it's Cookie store.
# Unlink this file after executing if it works.

Regards,
// NaHi
 
N

NAKAMURA, Hiroshi

Hi, again,
From: "NAKAMURA, Hiroshi"
Sent: Friday, October 03, 2003 12:05 AM
# Bear in mind it's Cookie store.
# Unlink this file after executing if it works.

Wrong. Without calling
client.save_cookie_store
explicitly, it must not be saved.

Regards,
// NaHi
 
A

Andi Scharfstein

Ara.T.Howard said:
After logging in [client.get('http://www.myskoda.de/index.html',
{"callname" => "mylogin", "password" => "mypass"})], which works as
expected,

so sending the authentication this way works.

Yes. After that, it get's stored in a cookie (sorry, forgot to post that
part).
i don't know this api - but is the autentication information sent
(automatically) again here? typically browsers do this for once
you've done it once, but i don't know if this object does that or not?

Yes, it recognizes that I am authorized to load the page. Try doing that
without logging in, you'll get an error.
So, the cookie stuff seems to work... the problem is that the CGI doesn't
seem to recognize or accept my input, but acts as if there was no input
at all. Hence my suspicion that I don't handle the POST request
correctly. I've tried adding the login data to the request, but that
doesn't change anything.
 
A

Andi Scharfstein

Hi,

I know nothing about this site but if the site use HTTP-Cookies,

client.set_cookie_store("cookie.dat")

before
After logging in [client.get('http://www.myskoda.de/index.html',
{"callname" => "mylogin", "password" => "mypass"})]
and

client.post('http://www.myskoda.de/emailsys/sms/sms.html', {"network"
=> "151", "number" => "12345678", "msg" => text})

might help.

Thanks for your input. I toyed around with that a bit and found out the
following:
client.set_cookie_store("cookie.dat") before logging on allows me to
authenticate at the server, making it a successful login. Leaving it out
leads to an error page ("Could not log in, please turn on cookies").
As I had that line in the script before, that doesn't change anything.
Sorry again I didn't mention it.
I tried inserting this line before the "Send SMS" request, which changes
the script's behaviour: The site now thinks that I have not logged on and
prompts me to do so (the error page I talked about in my other post). So,
I deleted it again.
Then, I tried changing the client.get to client.post and vice versa. This
proved more interesting:
When trying to provide login data via client.post (i.e. client.post
('http://www.myskoda.de/index.html',accept the login anymore. That is, I got the same message as before
("Could not log in"). So, something must be wrong with the POST method I
use to access the site.
I also tried changing the other POST request (Send SMS) to a GET, but
sadly, this didn't work... in both cases, all I get is a 200 OK and the
site loads as if I hadn't posted any data at all (except the login data
from the cookie, which obviously is still there). The errors and a
successful login are both handled by a 302 redirect (which I don't have
to follow, as I know the URLs I want to access).
So, are there any ideas on how to do the POST request differently so it
might work?
 
A

Andi Scharfstein

So, are there any ideas on how to do the POST request differently so
it might work?

By the way, dumping the output of the script to STDERR shows the POST
arguments and values as a text stream, like so:

number12345678network151msgHello there, test

for {"network" => "151", "number" => "12345678", "msg" => text}

Is that normal? I don't have a lot of experience with that library, nor
HTTP requests (as stated before)
 
A

Andi Scharfstein

By the way, dumping the output of the script to STDERR shows the POST
arguments and values as a text stream, like so:

number12345678network151msgHello there, test

for {"network" => "151", "number" => "12345678", "msg" => text}

Is that normal? I don't have a lot of experience with that library, nor
HTTP requests (as stated before)

Well, http://dom.neopoleon.com/commentview.aspx/c27f3f0d-9b2c-40b8-9607-
a84ced507aa3 (Yeah, I know. Don't say it) finally showed me how it was
done: posting "network=151&number=12345678&msg=#{text}" to the site does
seem to have the desired result. Thank you for your attention :)
 
N

NAKAMURA, Hiroshi

Hi,
From: "Andi Scharfstein" <[email protected]>
Sent: Friday, October 03, 2003 6:07 AM
finally showed me how it was
done: posting "network=151&number=12345678&msg=#{text}" to the site does
seem to have the desired result. Thank you for your attention :)

I'm sorry for your trouble... I seem to break the POSTing code
when I added streaming POST feature to http-access2.
I think your original code should work.

I'll dig into the code.

Regards,
// NaHi
 
N

NAKAMURA, Hiroshi

Hi,
From: "NAKAMURA, Hiroshi" <[email protected]>
Sent: Friday, October 03, 2003 5:27 PM

I'm sorry for your trouble... I seem to break the POSTing code
when I added streaming POST feature to http-access2.
I think your original code should work.

I fixed it and released 2.0.1 on RAA.
http://raa.ruby-lang.org/list.rhtml?name=http-access2

http-access2 gives something like the functionality of
libwww-perl (LWP) in Ruby. (Though I've never used LWP :)

Features;
- methods like GET/HEAD/POST via HTTP/1.1.
- asynchronous HTTP request
- HTTPS(SSL)
- by contrast with net/http in standard distribution;
- you don't have to care HTTP/1.1 persistent connection
(http-access2 cares instead of you).
- MT-safe
- streaming POST
- Cookies handling

Not supported now;
- Cache
- Rather advanced HTTP/1.1 usage such as Range, deflate, etc.
(of cource you can set it in header by yourself)
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top