Skip to content

Commit a6c055b

Browse files
committed
响应增加自定义Header
1 parent 572c843 commit a6c055b

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#HTTP
2+
##HTTP客户端
3+
###代码
4+
[使用Fluent API发起HTTP请求](cn/aofeng/demo/httpclient/FluentApi.java)
5+
6+
##HTTP服务端
7+
###代码
8+
[使用JDK中的API建立简单的HTTP Server](src/cn/aofeng/demo/httpclient/SimpleHttpServer.java)

src/cn/aofeng/demo/httpclient/SimpleHttpServer.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ public void handle(HttpExchange httpEx) throws IOException {
6262
// 返回响应
6363
String rc = "冒号后面是收到的请求,原样返回:"+content;
6464
byte[] temp = rc.getBytes(_charset);
65+
Headers outHeaders = httpEx.getResponseHeaders();
66+
outHeaders.set("ABC", "123");
6567
httpEx.sendResponseHeaders(200, temp.length);
6668
OutputStream outs = httpEx.getResponseBody();
6769
outs.write(temp);

0 commit comments

Comments
 (0)