Hızlı Konu Açma

Hızlı Konu Açmak için tıklayınız.

Son Mesajlar

Konulardaki Son Mesajlar

Reklam

Forumda Reklam Vermek İçin Bize Ulaşın

Basit Bir Http İstemcisi Örneği JAVA

BlackKey

Üye
Fenerbahçe
Kayıtlı Üye
Katılım
12 Eylül 2014
Mesajlar
167
Tepkime puanı
0
Puanları
0
Kod:
[COLOR=#B5B5B5][FONT=tahoma]import java.net.*; [/FONT][/COLOR]import java.io.*; 

public class SocketCat { 

public static **** main(String[] args) { 

for (int i = 0; i < args.length; i++) { 
int port = 80; 
String file = "/"; 
try { 
URL u = new URL(args[i]); 
if (u.getPort() != -1) port = u.getPort(); 
if (!(u.getProtocol().equalsIgnoreCase("http"))) { 
System.err.println("I only understand http."); 
continue; 
} 
if (!(u.getFile().equals(""))) file = u.getFile(); 
Socket s = new Socket(u.getHost(), port); 
OutputStream theOutput = s.getOutputStream(); 
PrintWriter pw = new PrintWriter(theOutput, false); 
pw.println("GET " + file + " HTTP/1.0"); 
pw.println("Accept: text/plain, text/html, text/*"); 
pw.println(); 
pw.flush(); 

InputStream in = s.getInputStream(); 
InputStreamReader isr = new InputStreamReader(in); 
BufferedReader br = new BufferedReader(isr, "ASCII"); 
String theLine; 
while ((theLine = br.readLine()) != null) { 
System.out.println(theLine); 
} 
} 
catch (MalformedURLException e) { 
System.err.println(args[i] + " is not a valid URL"); 
} 
catch (IOException ex) { 
System.err.println(ex); 
} 

} 

} 
 [COLOR=#B5B5B5][FONT=tahoma]}[/FONT][/COLOR]
 

Users Who Are Viewing This Konu (Users: 0, Guests: 1)

Üst