advance-practice1/web-server #1155
Replies: 6 comments 14 replies
-
问个问题 |
Beta Was this translation helpful? Give feedback.
-
use std::{
io::{prelude::*, BufReader},
net::{TcpListener, TcpStream},
};
fn main() {
let listener = TcpListener::bind("127.0.0.1:7878").unwrap();
for stream in listener.incoming() {
let stream = stream.unwrap();
handle_connection(stream);
}
}
fn handle_connection(mut stream: TcpStream) {
let buf_reader = BufReader::new(&mut stream);
let http_request: Vec<_> = buf_reader
.lines()
.map(|result| result.unwrap())
.take_while(|line| !line.is_empty())
.collect();
println!("Request: {:#?}", http_request);
} stream不是不可变的吗,怎么能当成可变传入函数里面 |
Beta Was this translation helpful? Give feedback.
-
请教个问题: |
Beta Was this translation helpful? Give feedback.
-
这里的format!("{status_line}\r\nContent-Length: {length}\r\n\r\n\n{contents}"); |
Beta Was this translation helpful? Give feedback.
-
试了,只能访问一次,然后服务器出错,在: |
Beta Was this translation helpful? Give feedback.
-
advance-practice1/web-server
https://course.rs/advance-practice1/web-server.html
Beta Was this translation helpful? Give feedback.
All reactions