• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Simulating Post in Java code.....

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Friends
I have written a piece of java code that simulates a POST method. the code works well in my friend's computer and gives me the expected HTML page output. But when I run at my comp at work place (a different network from the one my friend is connected to)....I get a connection time out error.
so I guess there is no problem with my code..I would be grateful if any of you guys out there..could help me solve the problem.Should I change some settings in my computer...or is there a way to tweak my code and get it running correctly. I even tried using the URL mentioned in the code accesing the HTML page thru browser..It works!!!...but when I simulate the POST Method in my code and try to make it run..(without using the browser) I get "java.net.ConnectException: Connection timed out: connect". Please help me...in finding the solution.
I have pasted my code below....
Thanks!
Srihari
/*******************************************
package Pratt;
import java.io.*;
import java.net.*;
import java.util.*;
public class Pratt {
URL url;
URLConnection urlConn;
DataOutputStream dout;
public Pratt() throws Exception {


url = new URL ("http://www2.ebi.ac.uk/cgi-
bin/prattparser.pl");

urlConn = url.openConnection();

urlConn.setDoInput (true);
urlConn.setDoOutput (true);
urlConn.setUseCaches (false);
urlConn.setRequestProperty("Content-
type", "application/x-www-form-urlencoded");

dout = new DataOutputStream
(urlConn.getOutputStream ());
String content =
"sequence=" + URLEncoder.encode ("aksjkljdklajdlk") +
"&USEDATA=" + URLEncoder.encode ("RUN PRATT") +
"&C%=" + URLEncoder.encode ("100.0")+
"&PP=" + URLEncoder.encode ("off")+
"&PL=" + URLEncoder.encode ("50")+
"&PN=" + URLEncoder.encode ("50") +
"&PX=" + URLEncoder.encode ("5")+
"&FN=" + URLEncoder.encode ("2")+
"&FL=" + URLEncoder.encode ("2")+
"&FP=" + URLEncoder.encode ("10")+
"&BI=" + URLEncoder.encode ("off")+
"&BN=" + URLEncoder.encode ("20")+
"&S=" + URLEncoder.encode ("info")+
"&G=" + URLEncoder.encode ("seq")+
"&E=" + URLEncoder.encode ("3")+
"&R=" + URLEncoder.encode ("on")+
"&RG=" + URLEncoder.encode ("off")+
"&OP=" + URLEncoder.encode ("on")+
"&ON=" + URLEncoder.encode ("50")+
"&OA=" + URLEncoder.encode ("50")+
"&M=" + URLEncoder.encode ("on")+
"&MR=" + URLEncoder.encode ("10")+
"&MV=" + URLEncoder.encode ("off");


dout.writeBytes (content);
dout.flush ();
dout.close ();
BufferedReader din = new BufferedReader(new
InputStreamReader(urlConn.getInputStream ()));
(urlConn.getInputStream ());
String str;

while (null != ((str = (din.readLine()))))
System.out.println (str);
din.close ();
}

public static void main(String[] args) {

try {
new Pratt();
}catch (Exception e) {
e.printStackTrace();
}

}

}
[ July 18, 2002: Message edited by: Srihari Venkatesan ]
[ July 19, 2002: Message edited by: Srihari Venkatesan ]
 
Ranch Hand
Posts: 4716
9
Scala Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
it has been a very long time since i wrote any java code and i did have problems getting the code to work with netscape(it is part of an applet). however you can compare your code to mine and see if there is anything you can try.
https://coderanch.com/t/113013/HTML-JavaScript/sending-HTML-form-data-java
 
reply
    Bookmark Topic Watch Topic
  • New Topic