12-19-2007 10:43 AM
private void sendRequest(String url)
{
try {
URLConnection urlc = (new URL(url)).openConnection();
urlc.connect(); //this line may be removed
InputStream stream = urlc.getInputStream();
int carac;
while ((carac = stream.read()) != -1)
{
System.out.println(carac + " - ");
}
System.out.println("end");
stream.close();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
private void mandarPedido(String url)
{
try {
byte [] data_bytes = {0}; //i need at least 1 byte
URLConnection conec = (new URL(url)).openConnection();
conec.connect();
boolean threw_exception = false;
InputStream stream = null;
do
{
//repeat until it works!!
try {
threw_exception = false;
stream = conec.getInputStream();
} catch (IOException e) {
conec = (new URL(url)).openConnection();
conec.connect();
if (e.getMessage().matches("^Server returned HTTP response code: [0-9]+ for URL:.*$"))
{
//I read the webscript error code
int errcode = new Integer(e.getMessage().replaceFirst("^Server returned HTTP response code: ([0-9]+) for URL:.*$", "$1")).intValue();
threw_exception = (errcode == 500);
if (errcode != 500)
{
//a real exception
throw e;
}
}
else if (stream == null)
{
threw_exception = true;
}
else
{
threw_exception = false;
throw e;
}
}
} while (threw_exception);
try
{
stream.read(data_bytes);
}
catch (NullPointerException npe)
{
npe.printStackTrace();
}
stream.close();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
12-19-2007 11:15 AM
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.