Khi thao tác với các website thì chúng ta có hai hành động, thứ nhất đó là gửi yêu cầu lên server và ta gọi là request, hành động thứ ha là server gửi trả kết quả về cho client và ta gọi là response. Mỗi hành động như vậy sẽ kèm các thông số kèm theo và các thông số đó ta gọi là Header Parameters. Trình duyệt và server sẽ dựa vào các thông số header này để trả dữ liệu và hiển thị dữ liệu cho phù hợp, vì vậy nó đóng vai trò khá là quan trọng đấy.

Note: Để xem các tham số đó bằng mắt thường thì bạn hãy sử dụng Firebug của Chrome nhé, nó nằm ở tab Network.

Nội dung chính

  • 1. Header Request Parameters
  • 2. Header Response Parameters
  • 3. Lời kết

1. Header Request Parameters

Header request parameters là các thông số kèm theo khi gửi yêu cầu lên server

Bạn dễ dàng nhập thấy các thông số thường gặp như HostUser-AgentCookie, … đấy là các tham số mặc định tự sinh ra bởi trình duyệt và bạn không thể thay đổi giá trị cho chúng, trừ khi bạn sử dụng CURL để tạo một request giả.

Trước đây mình thắc mắc tại sao Cookie được lưu ở trình duyệt client mà server có thể đọc được, kể từ ngày tìm hiểu về các tham số Header này mới hiểu là khi gửi request trình duyệt đã đính kèm thêm tham số này ở header.

2. Header Response Parameters

Header response parameters là các thông số kèm theo khi server gửi kết quả về cho client.

Các thông số thường thấy như Server, Last-ModiffiedContent-TypeContent-LengthContent-Encoding … Các thông số này ta có thể sử dụng htaccess hoặc hàm header trong PHP để can thiệp bổ sung hoặc thay đổi giá trị.

Ví dụ: Thay đổi định dạng Content-Type trả về là một hình ảnh PNG chứ không phải là text/plain, bạn sẽ đặt đoạn code sau ở đầu file PHP.

 

1
header('Content-Type: image/png');

 

3. Lời kết

Mỗi tham số mặc định sẽ có một nhiệm vụ cụ thể nên nếu thấy cần thiết thì bạn mới thay đổi giá trị cho nó, còn bình thường thì không cần thiết. Ví dụ như ở hình ảnh Header Response có tham số Content-Encoding = gzip là do mình đã sử dụng file .htaccess để nén trước khi gửi về client.

Ok bài này mang tính chất giới thiệu thôi, bạn chỉ cần hiểu trong các request sẽ có các tham số header kèm theo là được, sau này khi học nâng cao lên các Framework như NodeJS, CURL hoặc viết các web service thì bạn sẽ đụng tới nó khá nhiều.web

23 BÌNH LUẬN

  1. I love what you guys tend to be up too. Such clever work and exposure!
    Keep up the excellent works guys I’ve incorporated you guys to my own blogroll.

  2. หากคุณไม่มั่นใจในการเริ่มโปรเจ็คใหม่ของคุณ หรือต้องการทราบขอบเขตของงาน เราสามารถเป็นที่ปรึกษาในทุกข้อสงสัย และจะช่วยคุณตลอดการดำเนินงานของคุณ สามารถติดต่อเข้ามาพูดคุยกับเราก่อนได้

    You are employing a browser that isn’t supported by
    Fb, so we have redirected you to definitely a less
    complicated Model to supply you with the most effective working experience.

    It appears like you ended up misusing this feature by heading much too rapidly.
    You’ve been temporarily blocked from employing it.

    หากคุณต้องการงานภาพกราฟิกดีไซน์ที่มีคุณภาพในขอนแก่น เราคือคำตอบการงานกราฟิกชั้นนำในขอนแก่น ที่มีรูปแบบดีไซน์ที่หลากหลายและเป็นสากล

    เยส เว็บ ดีไซน์ สตูดิโอ เป็นบริษัทที่รับออกแบบเว็บไซต์ ที่เชี่ยวชาญในการออกแบบเว็บไซต์และพัฒนาเว็บไซต์ให้กับลูกค้าที่ขอนแก่น เราคือบริษัททำเว็บไซต์หนึ่งเดียวในขอนแก่น ที่มีการออกแบบที่โดดเด่นไม่เหมือนใคร

    ติวเตอร์ และผู้เชี่ยวชาญที่ให้ความรู้เฉพาะด้าน

    You happen to be employing a browser that may not supported by Fb, so we’ve redirected you to an easier Edition to supply you with
    the best knowledge.

    คุมงบได้เองมีผู้ช่วยดูแลจนจบงานตอบเร็วแน่นอนการันตีคุณภาพงาน

    กลยุทธ์เพื่อสร้างความได้เปรียบในตลาด

    It appears like you have been misusing this attribute by going as well quickly.
    You’ve been briefly blocked from applying it.

    เยส เว็บ ดีไซน์ สตูดิโอ บริษัทรับออกแบบเว็บไซต์ขอนแก่น รับทำเว็บขอนแก่น

    สิ่งที่จะได้รับเมื่อใช้บริการกับเรา

    บริการออกแบบเว็บไซต์ด้วยดีไซน์ชั้นนำของจังหวัดขอนแก่น

    ในฐานะการเป็นผู้นำทางด้านออกแบบ เราตั้งใจและหาวิธีทำให้ธุรกิจของคุณเป็นที่รู้จักกับลูกค้าและตรงต่อความต้องการ ต่อยอดธุรกิจ ขยายช่องทางการขาย
    และสร้างการรับรู้บนโลกออนไลน์

    ยกระดับธุรกิจของคุณกับผลลัพธ์ที่น่าพอใจ

    พวกเราจะสร้างธุรกิจของคุณที่ขอนแก่น
    ด้วยเว็บไซต์ที่มีคุณภาพสูงและอัตราการเข้าถึงที่มีประสิทธิภาพ

    You happen to be employing a browser that isn’t supported by
    Facebook, so we have redirected you to definitely a simpler Variation to give
    you the greatest encounter.

  3. I was suggested this blog through my cousin.
    I’m not sure whether this publish is written by
    him as nobody else recognise such specific about my difficulty.
    You are incredible! Thank you!

  4. You’ve made some decent points there. I looked on the web for more information about the issue and found
    most people will go along with your views on this web site.

  5. With havin so much content and articles do you ever run into any problems
    of plagorism or copyright violation? My website has a lot of completely unique content I’ve either authored myself or outsourced but it looks like a lot of
    it is popping it up all over the internet without my authorization.
    Do you know any solutions to help reduce content from being stolen?
    I’d really appreciate it.

  6. Hey would you mind sharing which blog platform you’re using?
    I’m looking to start my own blog soon but I’m having a difficult time deciding between BlogEngine/Wordpress/B2evolution and Drupal.
    The reason I ask is because your design seems different then most blogs
    and I’m looking for something completely unique.
    P.S Apologies for getting off-topic but I had to
    ask!

  7. Does your website have a contact page? I’m having trouble locating it
    but, I’d like to shoot you an e-mail. I’ve got some suggestions
    for your blog you might be interested in hearing.
    Either way, great site and I look forward to seeing it grow over time.

  8. Awesome things here. I’m very happy to see your
    post. Thank you so much and I’m having a look forward
    to contact you. Will you kindly drop me a mail?

  9. It is appropriate time to make some plans for the future and it is time to be
    happy. I have read this post and if I could I want to
    suggest you few interesting things or advice. Maybe you
    could write next articles referring to this article.
    I wish to read even more things about it!

  10. It’s amazing to visit this site and reading the views of all colleagues regarding this piece of writing, while I am also
    keen of getting knowledge.

  11. Hey just wanted to give you a quick heads up. The text in your
    content seem to be running off the screen in Firefox.

    I’m not sure if this is a formatting issue or something
    to do with web browser compatibility but I figured I’d post
    to let you know. The design look great though!
    Hope you get the issue solved soon. Kudos

  12. Great blog here! Also your web site loads up very fast!

    What web host are you using? Can I get your affiliate link to your host?
    I wish my site loaded up as fast as yours lol

  13. Normally I do not learn article on blogs, but I would like to say that this write-up very forced me to check
    out and do it! Your writing taste has been amazed me.
    Thanks, quite great post.

  14. You made some good points there. I checked on the net to learn more about the issue
    and found most people will go along with your views on this web site.

  15. Great post. I was checking constantly this
    blog and I am impressed! Extremely useful info specially the closing part 🙂
    I care for such info much. I used to be looking for this particular
    information for a long time. Thank you and best of luck.

  16. When I initially commented I seem to have clicked the -Notify me when new comments are added- checkbox and now each time a comment
    is added I get 4 emails with the exact same comment.

    There has to be an easy method you are able to remove me from that service?
    Thanks a lot!

  17. Pretty element of content. I simply stumbled upon your web
    site and in accession capital to say that I get in fact loved
    account your blog posts. Anyway I’ll be subscribing
    to your augment or even I success you get admission to persistently rapidly.

  18. Wow, incredible weblog format! How long have you been running a blog for?
    you make running a blog glance easy. The entire glance of your website
    is great, let alone the content!

THOÁT KHỎI BÌNH LUẬN

Please enter your comment!
Please enter your name here