Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

get Web Page problem

Status
Not open for further replies.

preethib

Programmer
Jul 20, 2000
39
IN
Hi guys,

I have this peice of Java code inherited. I can make a web page request by using the compiled Page.class file, and get the results from the host:port, without the intervention of any Browser cookie settings. The results are stored in page.txt. Now I want to send cookie information also, something like this:
"
GET /sites?qmy=test HTTP/1.0
Host:
Cookie: _USERKEY=AAAAS039c17791453400a1c206e0000194;_PG=1; _S_SETTINGS=v1:10:342:iso88591:
"
I mean to say send multiple lines of socket-writes along with Get request....

My Java program
"
Page.java
---------------
package com.av.rickey;

import java.net.*;
import java.io.*;


/**
* Page module to get a page
*/

public class Page
{
static String defaultUrl = " static String defaultFile = "page.txt";


URL url;
FileWriter file;

public Page()
{
try
{
url = new URL(defaultUrl);
}
catch(MalformedURLException e)
{
System.out.println(e);
}
try
{
file = new FileWriter(defaultFile);
}
catch (IOException e)
{
System.out.println(e);
}
}

public Page(String u)
{
try
{
url = new URL(u);
}
catch(MalformedURLException e)
{
System.out.println(e);
}
try
{
file = new FileWriter(defaultFile);
}
catch (IOException e)
{
System.out.println(e);
}
}

public Page(String u, String f)
{
try
{
url = new URL(u);
}
catch(MalformedURLException e)
{
System.out.println(e);
}
try
{
file = new FileWriter(f);
}
catch (IOException e)
{
System.out.println(e);
}
}

public String getPage(String u)
{
try
{
url = new URL(u);
}
catch(MalformedURLException e)
{
System.out.println(e);
}
try
{
file = new FileWriter(defaultFile);
}
catch (IOException e)
{
System.out.println(e);
}
return (getPage());
}

public String getPage(String u, String f)
{
try
{
url = new URL(u);
}
catch(MalformedURLException e)
{
System.out.println(e);
}
try
{
file = new FileWriter(f);
}
catch (IOException e)
{
System.out.println(e);
}

return (getPage());
}

public String getPage()
{
char[] cbuf = new char[1024];
String tmpStr;
String cont = new String();

try
{
URLConnection uc = url.openConnection();
InputStream is = uc.getInputStream();

BufferedReader in = new BufferedReader(new InputStreamReader(uc.getInputStream() ) );

while(true)
{
tmpStr = in.readLine();
if (tmpStr == null) break;
if (cont.length() == 0)
{
cont = tmpStr + "\n";
}
else
{
cont += tmpStr + "\n";
}
}

file.write(cont);
file.close();
}
catch(IOException e)
{
System.out.println(e);
}
return(cont);
}
}
--------------------
I am stuck with little Java sense.... any help with the way to handle it would be really appreciative,

Thanks,
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top