Mitglied seit: 07.10.2009
Forenbeiträge: 4
Besuche: 9
ich habe bereits viel rumprobiert jedoch gelang es mir nicht
wegen konvertierungsproblemen
[cli]import java.io.*;
import java.net.*;
public class Studium {
public static void main(String[] args) throws IOException{
if(args.length == 0){throw new IllegalArgumentException("define host!");}
OutputStream response = null;
if (args.length == 2) response = new FileOutputStream(args[1]);
else response = System.out;
URL url = new URL(args[0]);
String protocol = url.getProtocol();
if(!protocol.equals("http")){
throw new IllegalArgumentException("Please Enter the complete URL which includes protocol");}
String host = url.getHost();
int port = 80;
String[] Test={
"String1",
"String2"};
try {
for(int i = 0; i < Test.length; i++)
{
Socket socket = new Socket(host, port);
InputStream input = socket.getInputStream();
OutputStream request = socket.getOutputStream();
String s = "GET /" + Test + "\n";
request.write(s.getBytes());
request.flush();
byte[] buffer = new byte[4096];
int bytes;
while((bytes = input.read(buffer)) != -1){
response.write(buffer, 0, bytes);
}
request.close();
input.close();
socket.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}[/cli]
wegen konvertierungsproblemen
[cli]import java.io.*;
import java.net.*;
public class Studium {
public static void main(String[] args) throws IOException{
if(args.length == 0){throw new IllegalArgumentException("define host!");}
OutputStream response = null;
if (args.length == 2) response = new FileOutputStream(args[1]);
else response = System.out;
URL url = new URL(args[0]);
String protocol = url.getProtocol();
if(!protocol.equals("http")){
throw new IllegalArgumentException("Please Enter the complete URL which includes protocol");}
String host = url.getHost();
int port = 80;
String[] Test={
"String1",
"String2"};
try {
for(int i = 0; i < Test.length; i++)
{
Socket socket = new Socket(host, port);
InputStream input = socket.getInputStream();
OutputStream request = socket.getOutputStream();
String s = "GET /" + Test + "\n";
request.write(s.getBytes());
request.flush();
byte[] buffer = new byte[4096];
int bytes;
while((bytes = input.read(buffer)) != -1){
response.write(buffer, 0, bytes);
}
request.close();
input.close();
socket.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}[/cli]