Shop OBEX P1 Docs P2 Docs Learn Events
How to extract response text out of Response Header — Parallax Forums

How to extract response text out of Response Header

highplainsbubbahighplainsbubba Posts: 34
edited 2011-12-23 12:34 in Accessories
I have a html file that I am trying to use as a login page. It appears to work, I "post" the username and password to the spinneret and it returns a response header with either Sucess! or Failure. (See Below.) It splashes this across the login page and I don't quite know why. I know you can extract the response text out of an Ajax script, but I don't want to make a seperate Ajax request just for that. I would like to extract the "Sucess" from the response header of the login post, and "if response text = !Sucess (script), load the next page. I just can't see the forest for the trees. Could someone point me toward the right command to do this?

HTTP/1.1 200 OK Content-Type: text/html Server: Spinneret/2.1 Cache-Control: public Expires: Tue, 17 Jan 2001 09:53:44 GMT Sucess!
<html>
<head>
<title>Sanity Ridge Ranch</title>
<form id="post" name="post" method="post">

Username: <input type="text" name="user" />
<br /> 
Password: <input type="password" name="password" /> 
<br /> 

<input type="Submit" value="Log On" />
</form> 
<br /> 
</head>
<body>
<div style="width:720px;margin:auto;">
<h1 style="text-align:center;color:blue;">Sanity Ridge Ranch Log In Page</h1>
<br />
<br />


</body>
</html>

Comments

  • Mike GMike G Posts: 2,702
    edited 2011-12-22 20:25
    highplainsbubba, headers define an HTTP transaction. A header line has the format
    Name : Value
    

    The string "Success!" is not a valid header name or value. As a matter of fact "Success!" is part of the message body. Therefore, the string is displayed by the browser.
  • highplainsbubbahighplainsbubba Posts: 34
    edited 2011-12-23 06:32
    OK. that's clear enough. I need to capture the message body. So the only way to capture anything in an HTTP response ( to use as a variable), is to use an XMLHttpRequest? (I am incredibly new at this.) Perhaps I should concentrate on learning an XMLHttpRequest "Post" request. I had tried that, but managed to lock up the Mozilla browzer, so I stepped back to what worked. Thanks for the help.
  • sylvie369sylvie369 Posts: 1,622
    edited 2011-12-23 08:29
    OK. that's clear enough. I need to capture the message body. So the only way to capture anything in an HTTP response ( to use as a variable), is to use an XMLHttpRequest? (I am incredibly new at this.)

    There are plenty of other newbies (e.g., myself) out here who are benefiting from these questions and answers. Keep 'em coming.
  • Mike GMike G Posts: 2,702
    edited 2011-12-23 12:34
    highplainsbubba, How about responding with a landing page if the username and password is authenticated. If the credential are not authenticated, respond with the login page and a message; Invalid Login!

    There is a bit more that goes along with authentication like keeping the authentication token while clicking around on the site.
Sign In or Register to comment.