Get a String from an ASP via HttpUrlConnection Object

G

guyzdancin

I am trying to get a string from an active server page via an
HttpUrlConnection from a java application.

Following code does not work although a browser will display the the
string.

ACTIVE SERVER PAGE CODE

<%@ Language=VBScript %>
<HTML>
<HEAD>
<META NAME="DbLog" Content="Log in Data for LPT Test">
</HEAD>
<BODY>
<%
Response.write ("Hello World")
%>

</BODY>
</HTML>


JAVA APPLICATION CODE

try{
connection = (HttpURLConnection)url.openConnection();
}catch(IOException iOE1){}

String key = null;

try{//get string key from web server
connection.setFollowRedirects(true);
BufferedReader in = new BufferedReader(
new InputStreamReader(connection.getInputStream() ) );
key = in.readLine();
System.out.println(key);
}catch(Exception e){}



Thanks in advance for your help
 
B

ByteCoder

guyzdancin said:
I am trying to get a string from an active server page via an
HttpUrlConnection from a java application.

Following code does not work although a browser will display the the
string.

'a' browser would be Internet Explorer. Firefox and the like won't do
anything with VBScript.
ACTIVE SERVER PAGE CODE

<%@ Language=VBScript %>
<HTML>
<HEAD>
<META NAME="DbLog" Content="Log in Data for LPT Test">
</HEAD>
<BODY>
<%
Response.write ("Hello World")
%>

</BODY>
</HTML>


JAVA APPLICATION CODE

try{
connection = (HttpURLConnection)url.openConnection();
}catch(IOException iOE1){}

String key = null;

try{//get string key from web server
connection.setFollowRedirects(true);
BufferedReader in = new BufferedReader(
new InputStreamReader(connection.getInputStream() ) );
key = in.readLine();
System.out.println(key);
}catch(Exception e){}

A HttpURLConnection would download the source of the URL you connected
it to. in.readLine() would only return the first line of the source
code, which is <%@ Language=VBScript %> in your example.
 
C

Chris Smith

ByteCoder said:
'a' browser would be Internet Explorer. Firefox and the like won't do
anything with VBScript.

Actually, ASP is server-side, so pretty much any browser will display
that string.

However, the actual text returned would be something like:

----

<HTML>
<HEAD>
<META NAME="DbLog" Content="Log in Data for LPT Test">
</HEAD>
<BODY>
Hello World

</BODY>
</HTML>
----

And so (because there's a blank line at the top) the readLine() would
probably return an empty string. The solution would be to read the
entire response into an HTML parser, and then get the text of the page
from that. For something this simple, just stripping the tags would be
fine, and that can be done using regular expressions. However, a more
elaborate task would require a full parser, and a plan for how to deal
with certain HTML attributes that affect the text, such as bold or
italics.

It's worth noting that ASP doesn't *have* to be used to produce HTML.
For example, if you have control over the ASP and don't intend to
connect with a browser, you could use the following:

<%@ Language=VBScript %><% Response.write ("Hello World") %>

--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
B

ByteCoder

Chris said:
It's worth noting that ASP doesn't *have* to be used to produce HTML.
For example, if you have control over the ASP and don't intend to
connect with a browser, you could use the following:

<%@ Language=VBScript %><% Response.write ("Hello World") %>

Ok, thanks.

And I agree with the snipped part. ;)
 

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,774
Messages
2,569,598
Members
45,144
Latest member
KetoBaseReviews
Top