如何使用head http方法从请求中检索响应标头?
func SocketClient() {
conn, err := net.Dial("tcp", ":9000")
if err != nil {
log.Fatal(err)
}
defer conn.Close()
serverScan := bufio.NewScanner(conn)
inputScan := bufio.NewScanner(os.Stdin)
serverCh := ReadFully(serverScan)
inputCh := ReadFully(inputScan)
// create a wait group, this stops the SocketClient
// method from exiting until the workers are done.
var wg sync.WaitGroup
wg.Add(2)
go func() {
defer wg.Done()
for v := range inputCh {
_, _ = conn.Write([]byte(v))
}
}()
go func() {
defer wg.Done()
for v := range serverCh {
fmt.Printf("Received: %s\n", v)
}
}()
wg.Wait()
}
事件始终为空
解决方案
getCount(): Observable<number> {
return this.http.head(`${this.baseUrl}`)
.pipe(
map((event: any) => {
if (event instanceof HttpResponse) {
return +event.headers.get('header-name');
}
return 0;
}),
);
}