本文整理汇总了Java中com.sun.net.httpserver.HttpExchange.getRequestURI方法的典型用法代码示例。如果您正苦于以下问题:Java HttpExchange.getRequestURI方法的具体用法?Java HttpExchange.getRequestURI怎么用?Java HttpExchange.getRequestURI使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sun.net.httpserver.HttpExchange
的用法示例。
在下文中一共展示了HttpExchange.getRequestURI方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parseGetParameters
import com.sun.net.httpserver.HttpExchange; //导入方法依赖的package包/类
private Map<String, List<String>> parseGetParameters(HttpExchange exchange)
{
URI requestedUri = exchange.getRequestURI();
String query = requestedUri.getRawQuery();
return parseQuery(query, new HashMap<String, List<String>>());
}
示例2: handle
import com.sun.net.httpserver.HttpExchange; //导入方法依赖的package包/类
@Override
public void handle(HttpExchange t) throws IOException {
URI uri = t.getRequestURI();
String query = uri.getQuery();
if ("kill".equals(query)) {
// a kill request will stop the server
System.exit(0);
}
else if (query==null || query.length()==0 || "test".equals(query)) {
// an empty request or a test request will return an empty page;
// this is used to check whether the server is running
t.sendResponseHeaders(200, 0);
OutputStream os = t.getResponseBody();
os.write("Connected!".getBytes(Charset.forName("UTF-8")));
os.close();
}
}
示例3: getResponseType
import com.sun.net.httpserver.HttpExchange; //导入方法依赖的package包/类
private int getResponseType(HttpExchange exchange) {
URI uri = exchange.getRequestURI();
String rawQuery = uri.getRawQuery();
if (rawQuery == null) {
return HttpURLConnection.HTTP_OK;
}
if ("status=400".equals(rawQuery)) {
return HttpURLConnection.HTTP_BAD_REQUEST;
}
return HttpURLConnection.HTTP_OK;
}
示例4: handle
import com.sun.net.httpserver.HttpExchange; //导入方法依赖的package包/类
public void handle(HttpExchange t) throws IOException {
InputStream is = t.getRequestBody();
Headers map = t.getRequestHeaders();
Headers rmap = t.getResponseHeaders();
URI uri = t.getRequestURI();
debug("Server: received request for " + uri);
String path = uri.getPath();
if (path.endsWith("a.jar"))
aDotJar++;
else if (path.endsWith("b.jar"))
bDotJar++;
else if (path.endsWith("c.jar"))
cDotJar++;
else
System.out.println("Unexpected resource request" + path);
while (is.read() != -1);
is.close();
File file = new File(docsDir, path);
if (!file.exists())
throw new RuntimeException("Error: request for " + file);
long clen = file.length();
t.sendResponseHeaders (200, clen);
OutputStream os = t.getResponseBody();
FileInputStream fis = new FileInputStream(file);
try {
byte[] buf = new byte [16 * 1024];
int len;
while ((len=fis.read(buf)) != -1) {
os.write (buf, 0, len);
}
} catch (IOException e) {
e.printStackTrace();
}
fis.close();
os.close();
}
示例5: moved
import com.sun.net.httpserver.HttpExchange; //导入方法依赖的package包/类
void moved(HttpExchange t) throws IOException {
Headers req = t.getRequestHeaders();
Headers map = t.getResponseHeaders();
URI uri = t.getRequestURI();
String host = req.getFirst("Host");
String location = "http://" + host + uri.getPath() + "/";
map.set("Content-Type", "text/html");
map.set("Location", location);
t.sendResponseHeaders(301, -1);
t.close();
}
示例6: handle
import com.sun.net.httpserver.HttpExchange; //导入方法依赖的package包/类
public void handle(HttpExchange event) throws IOException {
URI uri = event.getRequestURI();
// favicon.ico, OPTION は 無視する
if (uri.getPath().endsWith("favicon.ico")
|| event.getRequestMethod().equalsIgnoreCase("OPTION")) {
sendOk(event);
return;
}
System.out.println(generateCurl(event));
sendOk(event);
}
示例7: handle
import com.sun.net.httpserver.HttpExchange; //导入方法依赖的package包/类
public void handle(HttpExchange t)
throws IOException {
InputStream is = t.getRequestBody();
Headers map = t.getRequestHeaders();
Headers rmap = t.getResponseHeaders();
OutputStream os = t.getResponseBody();
URI uri = t.getRequestURI();
String path = uri.getPath();
while (is.read() != -1) ;
is.close();
File f = new File(_docroot, path);
if (!f.exists()) {
notfound(t, path);
return;
}
String method = t.getRequestMethod();
if (method.equals("HEAD")) {
rmap.set("Content-Length", Long.toString(f.length()));
t.sendResponseHeaders(200, -1);
t.close();
} else if (!method.equals("GET")) {
t.sendResponseHeaders(405, -1);
t.close();
return;
}
if (path.endsWith(".html") || path.endsWith(".htm")) {
rmap.set("Content-Type", "text/html");
} else {
rmap.set("Content-Type", "text/plain");
}
t.sendResponseHeaders (200, f.length());
FileInputStream fis = new FileInputStream(f);
int count = 0;
try {
byte[] buf = new byte[16 * 1024];
int len;
while ((len = fis.read(buf)) != -1) {
os.write(buf, 0, len);
count += len;
}
} catch (IOException e) {
e.printStackTrace();
}
fis.close();
os.close();
}