How to add hyper header information?


#1

Hi all. I tried not to get body without header, I can’t get http://www.perlbot.net, and other sites can, I now want to add header, but did not succeed, please help to see, thank you! How to change it?

The 18 line error info: the trait hyper::header::Header is not implemented for &std::collections::HashMap<&str, &str>

https://play.rust-lang.org/?gist=ed3167d5d663f61362d0ae413609badb&version=stable&backtrace=0


#2

Use the types in the hyper::header module to control headers. For example:

    let res = client.get(url)
        .header(CacheControl(vec![CacheDirective::MaxAge(0)]))
        .header(Connection::keep_alive())
        .header(AcceptEncoding(vec![qitem(Encoding::Gzip), qitem(Encoding::Deflate)]))
        .send();

#3

mbrubeck: Thanks a lot!. Second questions, the page is charset=gb2312, println! can’t print, how to convert to utf8? What modules or functions can be work? thank you!!


#4

I would recommend the encoding crate


I doesn’t support gb2312, but it supports GBK and GB 18030, which I understand are extensions of gb2312, so it should probably work.


#5

krdln: Okay. thx a lot! This library should be able to solve my problem.