[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

http-access2 POSTing

Andi Scharfstein

10/2/2003 10:59:00 AM

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....) 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..../index.html',
{"callname" => "mylogin", "password" => "mypass"})], which works as
expected, I try to do the following:
client.post('http://www..../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?

--
Thanks: Andi S.
11 Answers

ahoward

10/2/2003 1:14:00 PM

0

NAKAMURA, Hiroshi

10/2/2003 3:05:00 PM

0

Hi,

> From: "Andi Scharfstein" <calvin8@t-online.de>
> Sent: Thursday, October 02, 2003 8:05 PM

> (http://www....)

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..../index.html',
> {"callname" => "mylogin", "password" => "mypass"})]

and

> client.post('http://www..../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

NAKAMURA, Hiroshi

10/2/2003 3:08:00 PM

0

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

Andi Scharfstein

10/2/2003 3:24:00 PM

0

"Ara.T.Howard" <ahoward@fsl.noaa.gov> wrote:

>> After logging in [client.get('http://www.myskoda.de/index...,
>> {"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 try to do the following:
>> client.post('http://www.myskoda.de/emailsys/sms/sms..., {"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?

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.

--
Bye: Andi S.

Andi Scharfstein

10/2/2003 4:11:00 PM

0

Hi,
"NAKAMURA, Hiroshi" <nakahiro@sarion.co.jp> wrote in
news:00dc01c388f6$8f5376d0$04e6a8c0@sarion.co.jp:

>> (http://www....)
>
> 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..../index.html',
>> {"callname" => "mylogin", "password" => "mypass"})]
>
> and
>
>> client.post('http://www..../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..../index.html',
>> {"callname" => "mylogin", "password" => "mypass"}), the server didn't
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?

--
Thx: Andi S.

Andi Scharfstein

10/2/2003 6:51:00 PM

0

Andi Scharfstein <ascalvin8@netscape.net> wrote in
news:Xns9408B9950EED0ascalvin8netscapenet@62.153.159.134:

> 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)

--
Bye: Andi S.

Andi Scharfstein

10/2/2003 8:49:00 PM

0

Andi Scharfstein <calvin8@t-online.de> wrote in
news:Xns9408D49377036ascalvin8netscapenet@62.153.159.134:

> 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-...
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 :)

--
Bye: Andi S.

NAKAMURA, Hiroshi

10/3/2003 8:28:00 AM

0

Hi,

> From: "Andi Scharfstein" <calvin8@t-online.de>
> 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

NAKAMURA, Hiroshi

10/4/2003 12:59:00 PM

0

Hi,

> From: "NAKAMURA, Hiroshi" <nakahiro@sarion.co.jp>
> Sent: Friday, October 03, 2003 5:27 PM

> > 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 fixed it and released 2.0.1 on RAA.
http://raa.ruby-lang.org/list.rhtml?name=ht...

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)

PV

9/4/2012 2:40:00 AM

0

John Fleming wrote:
> [Default] On Mon, 3 Sep 2012 15:16:12 -0600, while chained to a desk
> in the scriptorium "PV" <edrnouser@ spam telus.net> wrote:
>> $The Doctor wrote:
>> $> In article <7M71s.2094$Wo5.999@newsfe21.iad>,
>> $> PV <edrnouser@ spam telus.net> wrote:
>> $>> The Doctor wrote:
>> $>>> In article <0E71s.1508$wr2.88@newsfe08.iad>,
>> $
>> $<Snip>
>> $
>> $>>>>>> Feel free to look at what you call the "fundamentals", just
>> don't $>>>>>> try and impose them on others.
>> $>>>>>>
>> $>>>>>
>> $>>>>> So then you must be against the 10 Commandments being part of
>> the $>>>>> judicial code after all that is am imposition of
>> $>>>>> beliefs by YOUR standards.
>> $>>>>
>> $>>>> No that is a total red herring thrown by you to confuse the
>> $>>>> situation, I suspect all you have done is confuse yourself
>> $>>>>
>> $>>>> Keep your fundamentalist theology to yourself and your
>> "Church". $>>>> You are more then welcome to your beliefs as long as
>> you stop $>>>> attempting to force them on others. The world would
>> be a much $>>>> happier place if only people would follow this
>> simple rule. $>>>>
>> $>>>>
>> $>>>
>> $>>> No red herring. Thatis YOUR Logic PV.
>> $>>
>> $>> Please don't attempt to force your "logic" onto me, you and logic
>> $>> are not even passing acquaintances, never mind being close
>> friends. $>>
>> $>> Your statement "you must be against" is your words, not mind, and
>> $>> therefore makes the whole statement a red herring.
>> $>>
>> $>> Do you need to project your beliefs on others because you are not
>> $>> secure enough to stand alone?
>> $>>
>> $>>
>> $>
>> $> Typical PV always living in denial of the Truth.
>> $
>> $Typical Doc, unable to give a straight answer to anything, you
>> haven't the $foggiest notion as to what "truth" is, all you have is
>> ideas given to you by $others.
>
> I think you are wasting your breath PV. When you need a break, I know
> a lonely noise attenuation wall that would give you some interesting
> and stimulating conversation.

I realize that I am beating my head against the wall and totally wasting my
time. The noise attentuation wall sounds like a great conversationalist in
comparison to trying to hold an adult conversation with ID10T

--
PV

"If Inflammable means more flammable, then what does incompetent mean?'