try {
// Create a URLConnection object for a URL
URL url = new URL("http://hostname:80");
URLConnection conn = url.openConnection();
// List all the response headers from the server.
// Note: The first call to getHeaderFieldKey() will implicit send
// the HTTP request to the server.
for (int i=0; ; i++) {
String headerName = conn.getHeaderFieldKey(i);
String headerValue = conn.getHeaderField(i);
if (headerName == null && headerValue == null) {
// No more headers
break;
}
if (headerName == null) {
// The header value contains the server's HTTP version
}
}
} catch (Exception e) {
}
P3AC3MAK3R hat gesagt.:Hi,
maybe the following code snippet will help you out:
Code:try { // Create a URLConnection object for a URL URL url = new URL("http://hostname:80"); URLConnection conn = url.openConnection(); // List all the response headers from the server. // Note: The first call to getHeaderFieldKey() will implicit send // the HTTP request to the server. for (int i=0; ; i++) { String headerName = conn.getHeaderFieldKey(i); String headerValue = conn.getHeaderField(i); if (headerName == null && headerValue == null) { // No more headers break; } if (headerName == null) { // The header value contains the server's HTTP version } } } catch (Exception e) { }
Source: http://javaalmanac.com/egs/java.net/GetHeaders.html
public class HeaderTest {
public static void main(String[] args) {
// add the code from above here
}
}
P3AC3MAK3R hat gesagt.:Just create a new class like in the following example:
Code:public class HeaderTest { public static void main(String[] args) { // add the code from above here } }
btw: it's "compiler" and not "compilator".
Checkout the following tutorial for an introduction to the Java basics:
http://java.sun.com/docs/books/tutorial/reallybigindex.html
/tmp/21194/HeaderTest.java:6: cannot resolve symbol
symbol : class URL
location: class HeaderTest
URL url = new URL("http://www.tes.com");
^
/tmp/21194/HeaderTest.java:6: cannot resolve symbol
symbol : class URL
location: class HeaderTest
URL url = new URL("http://www.tes.com");
^
/tmp/21194/HeaderTest.java:7: cannot resolve symbol
symbol : class URLConnection
location: class HeaderTest
URLConnection conn = url.openConnection();
^
3 errors
public class HeaderTest {
public static void main(String[] args) {
try {
// Create a URLConnection object for a URL
URL url = new URL("http://www.mod-x.co.uk/mod_x_LeV_2/M_LeVeL3_od/mod_x_3.php");
URLConnection conn = url.openConnection();
// List all the response headers from the server.
// Note: The first call to getHeaderFieldKey() will implicit send
// the HTTP request to the server.
for (int i=0; ; i++) {
String headerName = conn.getHeaderFieldKey(i);
String headerValue = conn.getHeaderField(i);
if (headerName == null && headerValue == null) {
// No more headers
break;
}
if (headerName == null) {
// The header value contains the server's HTTP version
}
}
} catch (Exception e) {
}
}
}
Roar hat gesagt.:there is also an english forum on http://www.java-forum.org
import java.net.URL;
import java.net.URLConnection;
Roar hat gesagt.:the copmiler can't found these class because you have not imported it, but it's neccessary:
Code:import java.net.URL; import java.net.URLConnection;
Griffin hat gesagt.:If your program is finished, then you can put it in a jar file. So it gets started just by clicking on it. And the .class file can be used for other programs if there are any usefull methods or variables![]()
import java.net.URL;
import java.net.URLConnection;
public class HeaderTest {
public static void main(String[] args) {
try {
// Create a URLConnection object for a URL
URL url = new URL("http://www.mod-x.co.uk:80");
URLConnection conn = url.openConnection();
// List all the response headers from the server.
// Note: The first call to getHeaderFieldKey() will implicit send
// the HTTP request to the server.
for (int i=0; ; i++) {
String headerName = conn.getHeaderFieldKey(i);
String headerValue = conn.getHeaderField(i);
if (headerName == null && headerValue == null) {
// No more headers
break;
}
if (headerName == null) {
// The header value contains the server's HTTP version
}
}
} catch (Exception e) {
}
}
}
for (int i=0; ; i++)
for (int i=0; i<somethingbigger ; i++)
Griffin hat gesagt.:I copied the code into a file and I also tried to start your file. In both cases the are no errors but also nothing visual happens. Of course not, there is nothing in your code that would do an output.
But you have a for-lopp like this
don't you need something like thatCode:for (int i=0; ; i++)
Code:for (int i=0; i<somethingbigger ; i++)
Othwerwise the loop won't do anything!?!?
Ok, it works! Forget it.
And the loop is done 11 times.
Anonymous hat gesagt.:Griffin hat gesagt.:I copied the code into a file and I also tried to start your file. In both cases the are no errors but also nothing visual happens. Of course not, there is nothing in your code that would do an output.
But you have a for-lopp like this
don't you need something like thatCode:for (int i=0; ; i++)
Code:for (int i=0; i<somethingbigger ; i++)
Othwerwise the loop won't do anything!?!?
Ok, it works! Forget it.
And the loop is done 11 times.
Did you get it to run? In that case what was the output?