← Back to HTML Course | Chapter 9: Reference & Advanced | Lesson 7 of 9

HTML HTTP मैसेजेस

फ़र्ज़ करें आप किसी restaurant में खाना order कर रहे हैं। आप menu देखते हैं, अपना order एक slip of paper पर लिखते हैं, और उसे server को दे देते हैं (यह एक HTTP Request है)। chef आपका खाना बनाता है, और server उसे आपकी table पर आपके order की status दिखाने वाली receipt के साथ लाता है (यह एक HTTP Response है)। HTML HTTP messages वही order slips और receipts हैं। जब आप किसी link पर click करते हैं या कोई form submit करते हैं, तो आपका browser server को एक structured request message भेजता है, और server आपके webpage file और उसकी status details वाला एक response message लौटाता है। यह समझना कि ये messages कैसे structured होते हैं, तेज़, secure, और functional web applications बनाने के लिए ज़रूरी है।

HTTP मैसेजेस को समझना

HTTP (Hypertext Transfer Protocol) messages वह तरीका हैं जिससे आपके browser और web server के बीच data का आदान-प्रदान होता है।

ये सरल, plain-text messages के रूप में structured होते हैं: Request messages resources लाने के लिए browser द्वारा भेजे जाते हैं, और Response messages files के साथ server द्वारा वापस भेजे जाते हैं।

Note: active HTTP messages को real-time में देखने के लिए अपने browser के Developer Tools के network tab का इस्तेमाल करें।
Warning: Insecure HTTP connections messages को plain text में भेजते हैं, जिससे वे data interception के लिए vulnerable हो जाते हैं।

उदाहरण: Understanding HTTP Messages

markup
<!-- Request: GET /index.html HTTP/1.1 -->
<!-- Response: HTTP/1.1 200 OK -->
<a href="/index.html">Home</a>

HTTP रिक्वेस्ट हेडर्स

HTTP Request headers metadata fields हैं जो browser द्वारा भेजे जाते हैं ताकि server को बताया जा सके कि वह कौन-सा document type चाहता है, कौन-सा browser इस्तेमाल हो रहा है, या site के लिए कौन-से cookies save हैं।

Note: अपने request headers को अपने आप encrypt करने और user privacy बचाने के लिए secure HTTPS connections का इस्तेमाल करें।
Warning: सही request headers न भेजने से server गलत file format लौटा सकता है।

उदाहरण: HTTP Request Headers

markup
<!-- Request header: Accept: text/html -->
<!-- Request header: User-Agent: Mozilla/5.0 -->

HTTP रिस्पॉन्स हेडर्स

HTTP Response headers metadata fields हैं जो server द्वारा वापस भेजे जाते हैं ताकि browser को यह बताया जा सके कि लौटाए गए content को कैसे handle, cache, और securely display करना है।

Note: अपने pages के लिए default UTF-8 charset response header भेजने के लिए अपना server configure करें।
Warning: अगर आपके server के HTTP headers आपके HTML meta tags से contradict करते हैं, तो browser server settings को प्राथमिकता देगा, जिससे rendering bugs हो सकते हैं।

उदाहरण: HTTP Response Headers

markup
<!-- Response header: Content-Type: text/html; charset=UTF-8 -->
<meta charset="UTF-8">

स्टैंडर्ड HTTP स्टेटस कोड्स

हर HTTP response message में एक standard three-digit status code होता है जो browser को request के outcome की जानकारी देता है, जो categories में बंटा होता है: 2xx (Success), 3xx (Redirection), 4xx (Client Error), और 5xx (Server Error)।

Note: किसी page के स्थायी रूप से move होने पर सर्च इंजनों को बताने के लिए standard redirection codes (जैसे 301) का इस्तेमाल करें।
Warning: 4xx और 5xx error codes को handle न करने से आपका app crash हो सकता है और user experience खराब हो सकता है।

उदाहरण: Standard HTTP Status Codes

markup
<!-- 200 OK, 301 Moved Permanently, 404 Not Found, 500 Server Error -->
<a href="/new-page">301 redirected link</a>

फॉर्म मेथड्स और HTTP मैसेजिंग

जब कोई user HTML form submit करता है, तो method attribute (GET या POST) तय करता है कि data HTTP message के अंदर कैसे पैक किया जाए: GET query parameters को URL path में जोड़ता है, जबकि POST data को HTTP message body के अंदर सुरक्षित तरीके से पैक करता है।

Note: passwords जैसा संवेदनशील user data browser history loggers से छिपाने के लिए हमेशा POST method का इस्तेमाल करें।
Warning: files या sensitive password keys भेजने के लिए GET इस्तेमाल करने से आपकी application की security compromise हो सकती है।

उदाहरण: Form Methods and HTTP Messaging

markup
<form action="/search" method="get">
  <input type="text" name="q">
</form>
<form action="/login" method="post">
  <input type="password" name="password">
</form>
Live Example
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.