├── .gitignore ├── Makefile ├── README.md ├── README_current.json ├── book.json ├── book_current.json ├── node_modules └── src ├── README.md ├── SUMMARY.md ├── appendix ├── README.md ├── good_tutorial.md └── reference.md ├── assets ├── favicon.ico └── img │ ├── 0450D66D-6641-403F-BF7F-ED9496AD4A30.png │ ├── 0E984231-A46A-49DA-AB4C-8B1B6859BCE2.png │ ├── 1D928B86-A1C2-404B-A682-48332C1F71DF.png │ ├── 2B2421A4-B01C-49BA-B49F-607CD2E7A6C2.png │ ├── 2D3C5583-DE77-4BA8-A128-FCC1218B5FA8.png │ ├── 2F0FA94A-462F-49D5-8249-D7BFAE34CB76.png │ ├── 38CFDEB6-8637-4C7C-AC2E-14C7F3AD9B5A.png │ ├── 446072B2-ECCA-4D32-88C4-91CE64F85605.png │ ├── 4ACF224B-4768-406B-B28D-50F8131C38C4.png │ ├── 4DDE8C10-6593-4BFD-8BBC-A15A79698C25.png │ ├── 523C7AA5-AF8F-477A-A7CF-BA415AC37F8F.png │ ├── 58E15E6F-F862-4DFA-B248-EA981AB89FE6.png │ ├── 61CD3BDE-03EF-48A8-811E-DE5572656473.png │ ├── 644015DB-FDF6-48F8-AB2C-E68C76C63AD8.png │ ├── 665389BA-F1E4-4A17-B2FF-BEF7E773DD8D.png │ ├── 681BB8D6-73BC-4EAD-804E-4014E5C12299.png │ ├── 7C86AF70-EADF-4E11-A766-12467A62C778.png │ ├── 8495B70C-58BC-4786-940A-FC5834B12343.jpg │ ├── 8BE31A06-4506-4265-B436-888B09223C51.png │ ├── 9EED85A6-83B3-42DB-85D5-2B3B3E5F06A5.png │ ├── B7221FAE-3275-4973-88BC-D4E79EB59875.png │ ├── BD4592BC-6401-4D12-B84C-F50CFB53A3FB.png │ ├── D980D429-8ED2-4EAF-92A0-EC1AAD7E542B.png │ ├── DB7AD0DA-1C42-4504-B8C5-D8DFCE4444A4.png │ ├── chrome_address_with_zhcn.png │ ├── http_lib_js_fetch_resp.png │ ├── http_range_download.png │ ├── httpbin_get_resp.png │ ├── httpbin_ip_resp.png │ ├── httpbin_json_format.png │ ├── httpbin_json_formatted.png │ └── httpbin_org_home.png ├── http_detail ├── README.md ├── ch1_http_structure.md ├── ch2_http_header.md ├── ch3_http_req_param_encode.md ├── ch4_http_resp_status_code.md └── ch5_http_resp_data_format_json.md ├── http_intro ├── README.md ├── ch1_http_learn_purpose.md ├── ch2_http_intro.md ├── ch3_http_internal_process.md └── ch4_http_basic_logic.md └── http_related ├── README.md ├── ch2_http_api_design.md ├── ch3_http_note_summary.md ├── ch4_http_file_upload.md ├── ch5_mixed_content.md └── tool_lib ├── README.md ├── lib.md └── tool.md /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | output/ 3 | debug/ 4 | 5 | *.zip 6 | 7 | .DS_Store 8 | 9 | !src/**/output -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | include ../../common/honkit_makefile.mk -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # HTTP知识总结 2 | 3 | * 最新版本:`v3.4.1` 4 | * 更新时间:`20241007` 5 | 6 | ## 简介 7 | 8 | 总结HTTP技术相关内容。先进行了HTTP的简介,介绍了学习HTTP的目的,以及典型的HTTP的内部流程,以及总结了基本的逻辑。再进行HTTP的详细介绍,包括字段和结构,Header头,请求参数和编码,响应的状态码,响应数据的JSON格式等。再整理HTTP相关的一些内容,比如工具和不同语言的HTTP的网络库,以及如何进行后台HTTP相关的api接口设计,总结了一些相关心得,文件上传、混合内容等。最后附上一些HTTP相关的教程资料。 9 | 10 | ## 源码+浏览+下载 11 | 12 | 本书的各种源码、在线浏览地址、多种格式文件下载如下: 13 | 14 | ### HonKit源码 15 | 16 | * [crifan/http_summary: HTTP知识总结](https://github.com/crifan/http_summary) 17 | 18 | #### 如何使用此HonKit源码去生成发布为电子书 19 | 20 | 详见:[crifan/honkit_template: demo how to use crifan honkit template and demo](https://github.com/crifan/honkit_template) 21 | 22 | ### 在线浏览 23 | 24 | * [HTTP知识总结 book.crifan.org](https://book.crifan.org/books/http_summary/website/) 25 | * [HTTP知识总结 crifan.github.io](https://crifan.github.io/http_summary/website/) 26 | 27 | ### 离线下载阅读 28 | 29 | * [HTTP知识总结 PDF](https://book.crifan.org/books/http_summary/pdf/http_summary.pdf) 30 | * [HTTP知识总结 ePub](https://book.crifan.org/books/http_summary/epub/http_summary.epub) 31 | * [HTTP知识总结 Mobi](https://book.crifan.org/books/http_summary/mobi/http_summary.mobi) 32 | 33 | ## 版权和用途说明 34 | 35 | 此电子书教程的全部内容,如无特别说明,均为本人原创。其中部分内容参考自网络,均已备注了出处。如发现有侵权,请通过邮箱联系我 `admin 艾特 crifan.com`,我会尽快删除。谢谢合作。 36 | 37 | 各种技术类教程,仅作为学习和研究使用。请勿用于任何非法用途。如有非法用途,均与本人无关。 38 | 39 | ## 鸣谢 40 | 41 | 感谢我的老婆**陈雪**的包容理解和悉心照料,才使得我`crifan`有更多精力去专注技术专研和整理归纳出这些电子书和技术教程,特此鸣谢。 42 | 43 | ## 其他 44 | 45 | ### 作者的其他电子书 46 | 47 | 本人`crifan`还写了其他`150+`本电子书教程,感兴趣可移步至: 48 | 49 | [crifan/crifan_ebook_readme: Crifan的电子书的使用说明](https://github.com/crifan/crifan_ebook_readme) 50 | 51 | ### 关于作者 52 | 53 | 关于作者更多介绍,详见: 54 | 55 | [关于CrifanLi李茂 – 在路上](https://www.crifan.org/about/) 56 | -------------------------------------------------------------------------------- /README_current.json: -------------------------------------------------------------------------------- 1 | { 2 | "latestVersion": "v3.4.1", 3 | "lastUpdate": "20241007", 4 | "gitRepoName": "http_summary", 5 | "bookName": "HTTP知识总结", 6 | "bookDescription": "总结HTTP技术相关内容。先进行了HTTP的简介,介绍了学习HTTP的目的,以及典型的HTTP的内部流程,以及总结了基本的逻辑。再进行HTTP的详细介绍,包括字段和结构,Header头,请求参数和编码,响应的状态码,响应数据的JSON格式等。再整理HTTP相关的一些内容,比如工具和不同语言的HTTP的网络库,以及如何进行后台HTTP相关的api接口设计,总结了一些相关心得,文件上传、混合内容等。最后附上一些HTTP相关的教程资料。" 7 | } -------------------------------------------------------------------------------- /book.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "HTTP知识总结", 3 | "description": "总结HTTP技术相关内容。先进行了HTTP的简介,介绍了学习HTTP的目的,以及典型的HTTP的内部流程,以及总结了基本的逻辑。再进行HTTP的详细介绍,包括字段和结构,Header头,请求参数和编码,响应的状态码,响应数据的JSON格式等。再整理HTTP相关的一些内容,比如工具和不同语言的HTTP的网络库,以及如何进行后台HTTP相关的api接口设计,总结了一些相关心得,文件上传、混合内容等。最后附上一些HTTP相关的教程资料。", 4 | "pluginsConfig": { 5 | "github-buttons": { 6 | "buttons": [ 7 | { 8 | "repo": "http_summary", 9 | "user": "crifan", 10 | "type": "star", 11 | "count": true, 12 | "size": "small" 13 | }, 14 | { 15 | "user": "crifan", 16 | "type": "follow", 17 | "width": "120", 18 | "count": false, 19 | "size": "small" 20 | } 21 | ] 22 | }, 23 | "sitemap-general": { 24 | "prefix": "https://book.crifan.org/books/http_summary/website/" 25 | }, 26 | "toolbar-button": { 27 | "url": "https://book.crifan.org/books/http_summary/pdf/http_summary.pdf", 28 | "icon": "fa-file-pdf-o", 29 | "label": "下载PDF" 30 | }, 31 | "theme-default": { 32 | "showLevel": true 33 | }, 34 | "disqus": { 35 | "shortName": "crifan" 36 | }, 37 | "prism": { 38 | "css": [ 39 | "prism-themes/themes/prism-atom-dark.css" 40 | ] 41 | }, 42 | "sharing": { 43 | "douban": false, 44 | "facebook": true, 45 | "google": false, 46 | "hatenaBookmark": false, 47 | "instapaper": false, 48 | "line": false, 49 | "linkedin": false, 50 | "messenger": false, 51 | "pocket": false, 52 | "qq": true, 53 | "qzone": false, 54 | "stumbleupon": false, 55 | "twitter": true, 56 | "viber": false, 57 | "vk": false, 58 | "weibo": true, 59 | "whatsapp": false, 60 | "all": [ 61 | "douban", 62 | "facebook", 63 | "google", 64 | "instapaper", 65 | "line", 66 | "linkedin", 67 | "messenger", 68 | "pocket", 69 | "qq", 70 | "qzone", 71 | "stumbleupon", 72 | "twitter", 73 | "viber", 74 | "vk", 75 | "weibo", 76 | "whatsapp" 77 | ] 78 | }, 79 | "tbfed-pagefooter": { 80 | "copyright": "crifan.org,使用署名4.0国际(CC BY 4.0)协议发布", 81 | "modify_label": "最后更新:", 82 | "modify_format": "YYYY-MM-DD HH:mm:ss" 83 | }, 84 | "donate": { 85 | "wechat": "https://www.crifan.org/files/res/crifan_com/crifan_wechat_pay.jpg", 86 | "alipay": "https://www.crifan.org/files/res/crifan_com/crifan_alipay_pay.jpg", 87 | "title": "", 88 | "button": "打赏", 89 | "alipayText": "支付宝打赏给Crifan", 90 | "wechatText": "微信打赏给Crifan" 91 | } 92 | }, 93 | "author": "Crifan Li ", 94 | "language": "zh-hans", 95 | "root": "./src", 96 | "links": { 97 | "sidebar": { 98 | "主页": "http://www.crifan.org" 99 | } 100 | }, 101 | "plugins": [ 102 | "theme-comscore", 103 | "anchors", 104 | "expandable-menu", 105 | "-lunr", 106 | "-search", 107 | "search-plus", 108 | "disqus", 109 | "-highlight", 110 | "prism", 111 | "prism-themes", 112 | "github-buttons", 113 | "-splitter", 114 | "splitter-nosessionbutcookie", 115 | "-sharing", 116 | "sharing-plus", 117 | "tbfed-pagefooter", 118 | "donate", 119 | "sitemap-general", 120 | "copy-code-button", 121 | "blockquote-callout", 122 | "toolbar-button" 123 | ] 124 | } -------------------------------------------------------------------------------- /book_current.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "HTTP知识总结", 3 | "description": "总结HTTP技术相关内容。先进行了HTTP的简介,介绍了学习HTTP的目的,以及典型的HTTP的内部流程,以及总结了基本的逻辑。再进行HTTP的详细介绍,包括字段和结构,Header头,请求参数和编码,响应的状态码,响应数据的JSON格式等。再整理HTTP相关的一些内容,比如工具和不同语言的HTTP的网络库,以及如何进行后台HTTP相关的api接口设计,总结了一些相关心得,文件上传、混合内容等。最后附上一些HTTP相关的教程资料。", 4 | "pluginsConfig": { 5 | "github-buttons": { 6 | "buttons": [ 7 | { 8 | "repo": "http_summary" 9 | } 10 | ] 11 | }, 12 | "sitemap-general": { 13 | "prefix": "https://book.crifan.org/books/http_summary/website/" 14 | }, 15 | "toolbar-button": { 16 | "url": "https://book.crifan.org/books/http_summary/pdf/http_summary.pdf" 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /node_modules: -------------------------------------------------------------------------------- 1 | ../../generated/honkit/node_modules -------------------------------------------------------------------------------- /src/README.md: -------------------------------------------------------------------------------- 1 | # HTTP知识总结 2 | 3 | * 最新版本:`v3.4.1` 4 | * 更新时间:`20241007` 5 | 6 | ## 简介 7 | 8 | 总结HTTP技术相关内容。先进行了HTTP的简介,介绍了学习HTTP的目的,以及典型的HTTP的内部流程,以及总结了基本的逻辑。再进行HTTP的详细介绍,包括字段和结构,Header头,请求参数和编码,响应的状态码,响应数据的JSON格式等。再整理HTTP相关的一些内容,比如工具和不同语言的HTTP的网络库,以及如何进行后台HTTP相关的api接口设计,总结了一些相关心得,文件上传、混合内容等。最后附上一些HTTP相关的教程资料。 9 | 10 | ## 源码+浏览+下载 11 | 12 | 本书的各种源码、在线浏览地址、多种格式文件下载如下: 13 | 14 | ### HonKit源码 15 | 16 | * [crifan/http_summary: HTTP知识总结](https://github.com/crifan/http_summary) 17 | 18 | #### 如何使用此HonKit源码去生成发布为电子书 19 | 20 | 详见:[crifan/honkit_template: demo how to use crifan honkit template and demo](https://github.com/crifan/honkit_template) 21 | 22 | ### 在线浏览 23 | 24 | * [HTTP知识总结 book.crifan.org](https://book.crifan.org/books/http_summary/website/) 25 | * [HTTP知识总结 crifan.github.io](https://crifan.github.io/http_summary/website/) 26 | 27 | ### 离线下载阅读 28 | 29 | * [HTTP知识总结 PDF](https://book.crifan.org/books/http_summary/pdf/http_summary.pdf) 30 | * [HTTP知识总结 ePub](https://book.crifan.org/books/http_summary/epub/http_summary.epub) 31 | * [HTTP知识总结 Mobi](https://book.crifan.org/books/http_summary/mobi/http_summary.mobi) 32 | 33 | ## 版权和用途说明 34 | 35 | 此电子书教程的全部内容,如无特别说明,均为本人原创。其中部分内容参考自网络,均已备注了出处。如发现有侵权,请通过邮箱联系我 `admin 艾特 crifan.com`,我会尽快删除。谢谢合作。 36 | 37 | 各种技术类教程,仅作为学习和研究使用。请勿用于任何非法用途。如有非法用途,均与本人无关。 38 | 39 | ## 鸣谢 40 | 41 | 感谢我的老婆**陈雪**的包容理解和悉心照料,才使得我`crifan`有更多精力去专注技术专研和整理归纳出这些电子书和技术教程,特此鸣谢。 42 | 43 | ## 其他 44 | 45 | ### 作者的其他电子书 46 | 47 | 本人`crifan`还写了其他`150+`本电子书教程,感兴趣可移步至: 48 | 49 | [crifan/crifan_ebook_readme: Crifan的电子书的使用说明](https://github.com/crifan/crifan_ebook_readme) 50 | 51 | ### 关于作者 52 | 53 | 关于作者更多介绍,详见: 54 | 55 | [关于CrifanLi李茂 – 在路上](https://www.crifan.org/about/) 56 | -------------------------------------------------------------------------------- /src/SUMMARY.md: -------------------------------------------------------------------------------- 1 | # HTTP知识总结 2 | 3 | 4 | * [前言](README.md) 5 | 6 | * [HTTP简介](http_intro/README.md) 7 | * [HTTP学习目的](http_intro/ch1_http_learn_purpose.md) 8 | * [HTTP简介](http_intro/ch2_http_intro.md) 9 | * [HTTP内部流程](http_intro/ch3_http_internal_process.md) 10 | * [HTTP基本逻辑总结](http_intro/ch4_http_basic_logic.md) 11 | 12 | * [HTTP详解](http_detail/README.md) 13 | * [HTTP的典型结构](http_detail/ch1_http_structure.md) 14 | * [HTTP的Header头](http_detail/ch2_http_header.md) 15 | * [HTTP的请求参数和编码](http_detail/ch3_http_req_param_encode.md) 16 | * [HTTP的响应的状态码](http_detail/ch4_http_resp_status_code.md) 17 | * [HTTP的响应数据格式JSON](http_detail/ch5_http_resp_data_format_json.md) 18 | 19 | * [HTTP相关](http_related/README.md) 20 | * [HTTP的工具和库](http_related/tool_lib/README.md) 21 | * [HTTP工具](http_related/tool_lib/tool.md) 22 | * [HTTP库](http_related/tool_lib/lib.md) 23 | * [HTTP的后台API设计](http_related/ch2_http_api_design.md) 24 | * [HTTP相关心得](http_related/ch3_http_note_summary.md) 25 | * [HTTP的文件上传](http_related/ch4_http_file_upload.md) 26 | * [混合内容](http_related/ch5_mixed_content.md) 27 | 28 | * [附录](appendix/README.md) 29 | * [优质教程](appendix/good_tutorial.md) 30 | * [参考资料](appendix/reference.md) 31 | -------------------------------------------------------------------------------- /src/appendix/README.md: -------------------------------------------------------------------------------- 1 | # 附录 2 | 3 | 整理出一些教程、参考资料等内容供参考。 4 | 5 | -------------------------------------------------------------------------------- /src/appendix/good_tutorial.md: -------------------------------------------------------------------------------- 1 | # 优质教程 2 | 3 | * [HTTP 协议入门 - 阮一峰的网络日志](http://www.ruanyifeng.com/blog/2016/08/http.html) 4 | * [curl网站开发指南 - 阮一峰的网络日志](http://www.ruanyifeng.com/blog/2011/09/curl.html) 5 | -------------------------------------------------------------------------------- /src/appendix/reference.md: -------------------------------------------------------------------------------- 1 | # 参考资料 2 | 3 | * 【已解决】PySpider中使用多贝云IP代理池实现每次请求IP都不同 4 | * 【整理Book】Web前端三剑客:HTML+CSS+JS 5 | * 6 | * [【未解决】给Axios的http请求添加公共处理部分](http://www.crifan.com/js_axios_http_request_add_common_process_part) 7 | * [【整理】Httpbin免费提供HTTP请求和响应的测试网站](http://www.crifan.com/http_tool_free_httpbin_test_request_and_response_website) 8 | * [【已解决】ReactJS中好用的获取网络数据的http库](http://www.crifan.com/reactjs_good_network_http_lib) 9 | * [CORS开发总结](https://book.crifan.com/books/cors_dev_ummary/website/) 10 | * [【已解决】JS中如何实现将字典变量去url的encode](http://www.crifan.com/js_how_dict_json_url_encode_to_query_parameter) 11 | * [【已解决】iOS中Alamofire参数解析JSONEncoding出错 – 在路上](https://www.crifan.com/ios_alamofire_parameter_parse_jsonencoding_error/) 12 | * 13 | * [URL encoding the space character: + or %20? - Stack Overflow](https://stackoverflow.com/questions/1634271/url-encoding-the-space-character-or-20) 14 | * [Percent-encoding - Wikipedia](https://en.wikipedia.org/wiki/URL_encoding) 15 | * [GitHub - Alamofire/Alamofire: Elegant HTTP Networking in Swift](https://github.com/Alamofire/Alamofire) 16 | * [GitHub - requests/requests: Python HTTP Requests for Humans™ ✨🍰✨](https://github.com/requests/requests) 17 | * [python中 urllib, urllib2, httplib, httplib2 几个库的区别](https://my.oschina.net/sukai/blog/611451) 18 | * [21.11. http — HTTP modules — Python 3.6.3rc1 documentation](https://docs.python.org/3/library/http.html) 19 | * [HTTP请求与响应的知识点总结 - 简书](http://www.jianshu.com/p/88ad17126cb2) 20 | * [20.5. urllib — Open arbitrary resources by URL — Python 2.7.14 documentation](https://docs.python.org/2/library/urllib.html) 21 | * [HTTP请求响应报文&&相关状态码&&GET\_POST请求方法 总结](https://m.2cto.com/net/201607/530174.html) 22 | * [url encoding - How to urlencode a querystring in Python? - Stack Overflow](https://stackoverflow.com/questions/5607551/how-to-urlencode-a-querystring-in-python) 23 | * [HTTP协议详细总结 - 周东尧的个人页面](https://my.oschina.net/fairy1674/blog/735588) 24 | * [Get Started - PayPal Developer](https://developer.paypal.com/docs/api/overview/) 25 | * [Status Codes - Flask API](http://www.flaskapi.org/api-guide/status-codes/) 26 | * [Status codes in HTTP](https://www.w3.org/Protocols/HTTP/HTRESP.html) 27 | * [HTTP头部详解-zooyo-ChinaUnix博客](http://blog.chinaunix.net/uid-10540984-id-3130355.html) 28 | * [HTTP头信息详解-转 - chuncn - 博客园](http://www.cnblogs.com/chuncn/archive/2011/04/10/2011701.html) 29 | * [HTTP Header 详解\_知识库\_博客园](http://kb.cnblogs.com/page/92320/) 30 | * [HTTP 方法:GET 对比 POST](http://www.w3school.com.cn/tags/html_ref_httpmethods.asp) 31 | * [List of HTTP header fields - Wikipedia, the free encyclopedia](https://en.wikipedia.org/wiki/List_of_HTTP_header_fields) 32 | * [HTTP 教程 \| 菜鸟教程](http://www.runoob.com/http/http-tutorial.html) 33 | * [HTTP Header 详解\_知识库\_博客园](http://kb.cnblogs.com/page/92320/) 34 | * [HTTP/1.1: Header Field Definitions](http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html) 35 | * [Requests Header \| Http Header](http://www.sojson.com/httpRequest/) 36 | * [HTTP content-type \| 菜鸟教程](http://www.runoob.com/http/http-content-type.html) 37 | * [403 Forbidden vs 401 Unauthorized HTTP responses - Stack Overflow](http://stackoverflow.com/questions/3297048/403-forbidden-vs-401-unauthorized-http-responses) 38 | * [HTTP/1.1: Status Code Definitions](http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html) 39 | * [Fetch Standard](https://fetch.spec.whatwg.org/#biblio-mix) 40 | * [Mixed Content](https://w3c.github.io/webappsec-mixed-content/) 41 | * [什么是混合内容?|Web | Google Developers](https://developers.google.com/web/fundamentals/security/prevent-mixed-content/what-is-mixed-content?hl=zh-cn) 42 | * [关于启用 HTTPS 的一些经验分享(一) | JerryQu 的小站](https://imququ.com/post/sth-about-switch-to-https.html) 43 | * [混合内容 - 安全 | MDN](https://developer.mozilla.org/zh-CN/docs/Security/MixedContent) 44 | * [XTM Connect SDK – REST API](https://www.xtm-cloud.com/rest-api/#tag/HTTP-Codes) 45 | * [Vue乱搞系列之axios发起表单请求 - 简书](https://www.jianshu.com/p/b22d03dfe006) 46 | * [Vue.js 学习系列三——axios 学习实践 - 前端 - 掘金](https://juejin.im/entry/587599388d6d810058a7a41a) 47 | * [axios/axios: Promise based HTTP client for the browser and node.js](https://github.com/axios/axios) 48 | * -------------------------------------------------------------------------------- /src/assets/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crifan/http_summary/5df18472b7caafb659e5c8665d320aea16654b70/src/assets/favicon.ico -------------------------------------------------------------------------------- /src/assets/img/0450D66D-6641-403F-BF7F-ED9496AD4A30.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crifan/http_summary/5df18472b7caafb659e5c8665d320aea16654b70/src/assets/img/0450D66D-6641-403F-BF7F-ED9496AD4A30.png -------------------------------------------------------------------------------- /src/assets/img/0E984231-A46A-49DA-AB4C-8B1B6859BCE2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crifan/http_summary/5df18472b7caafb659e5c8665d320aea16654b70/src/assets/img/0E984231-A46A-49DA-AB4C-8B1B6859BCE2.png -------------------------------------------------------------------------------- /src/assets/img/1D928B86-A1C2-404B-A682-48332C1F71DF.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crifan/http_summary/5df18472b7caafb659e5c8665d320aea16654b70/src/assets/img/1D928B86-A1C2-404B-A682-48332C1F71DF.png -------------------------------------------------------------------------------- /src/assets/img/2B2421A4-B01C-49BA-B49F-607CD2E7A6C2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crifan/http_summary/5df18472b7caafb659e5c8665d320aea16654b70/src/assets/img/2B2421A4-B01C-49BA-B49F-607CD2E7A6C2.png -------------------------------------------------------------------------------- /src/assets/img/2D3C5583-DE77-4BA8-A128-FCC1218B5FA8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crifan/http_summary/5df18472b7caafb659e5c8665d320aea16654b70/src/assets/img/2D3C5583-DE77-4BA8-A128-FCC1218B5FA8.png -------------------------------------------------------------------------------- /src/assets/img/2F0FA94A-462F-49D5-8249-D7BFAE34CB76.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crifan/http_summary/5df18472b7caafb659e5c8665d320aea16654b70/src/assets/img/2F0FA94A-462F-49D5-8249-D7BFAE34CB76.png -------------------------------------------------------------------------------- /src/assets/img/38CFDEB6-8637-4C7C-AC2E-14C7F3AD9B5A.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crifan/http_summary/5df18472b7caafb659e5c8665d320aea16654b70/src/assets/img/38CFDEB6-8637-4C7C-AC2E-14C7F3AD9B5A.png -------------------------------------------------------------------------------- /src/assets/img/446072B2-ECCA-4D32-88C4-91CE64F85605.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crifan/http_summary/5df18472b7caafb659e5c8665d320aea16654b70/src/assets/img/446072B2-ECCA-4D32-88C4-91CE64F85605.png -------------------------------------------------------------------------------- /src/assets/img/4ACF224B-4768-406B-B28D-50F8131C38C4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crifan/http_summary/5df18472b7caafb659e5c8665d320aea16654b70/src/assets/img/4ACF224B-4768-406B-B28D-50F8131C38C4.png -------------------------------------------------------------------------------- /src/assets/img/4DDE8C10-6593-4BFD-8BBC-A15A79698C25.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crifan/http_summary/5df18472b7caafb659e5c8665d320aea16654b70/src/assets/img/4DDE8C10-6593-4BFD-8BBC-A15A79698C25.png -------------------------------------------------------------------------------- /src/assets/img/523C7AA5-AF8F-477A-A7CF-BA415AC37F8F.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crifan/http_summary/5df18472b7caafb659e5c8665d320aea16654b70/src/assets/img/523C7AA5-AF8F-477A-A7CF-BA415AC37F8F.png -------------------------------------------------------------------------------- /src/assets/img/58E15E6F-F862-4DFA-B248-EA981AB89FE6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crifan/http_summary/5df18472b7caafb659e5c8665d320aea16654b70/src/assets/img/58E15E6F-F862-4DFA-B248-EA981AB89FE6.png -------------------------------------------------------------------------------- /src/assets/img/61CD3BDE-03EF-48A8-811E-DE5572656473.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crifan/http_summary/5df18472b7caafb659e5c8665d320aea16654b70/src/assets/img/61CD3BDE-03EF-48A8-811E-DE5572656473.png -------------------------------------------------------------------------------- /src/assets/img/644015DB-FDF6-48F8-AB2C-E68C76C63AD8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crifan/http_summary/5df18472b7caafb659e5c8665d320aea16654b70/src/assets/img/644015DB-FDF6-48F8-AB2C-E68C76C63AD8.png -------------------------------------------------------------------------------- /src/assets/img/665389BA-F1E4-4A17-B2FF-BEF7E773DD8D.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crifan/http_summary/5df18472b7caafb659e5c8665d320aea16654b70/src/assets/img/665389BA-F1E4-4A17-B2FF-BEF7E773DD8D.png -------------------------------------------------------------------------------- /src/assets/img/681BB8D6-73BC-4EAD-804E-4014E5C12299.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crifan/http_summary/5df18472b7caafb659e5c8665d320aea16654b70/src/assets/img/681BB8D6-73BC-4EAD-804E-4014E5C12299.png -------------------------------------------------------------------------------- /src/assets/img/7C86AF70-EADF-4E11-A766-12467A62C778.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crifan/http_summary/5df18472b7caafb659e5c8665d320aea16654b70/src/assets/img/7C86AF70-EADF-4E11-A766-12467A62C778.png -------------------------------------------------------------------------------- /src/assets/img/8495B70C-58BC-4786-940A-FC5834B12343.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crifan/http_summary/5df18472b7caafb659e5c8665d320aea16654b70/src/assets/img/8495B70C-58BC-4786-940A-FC5834B12343.jpg -------------------------------------------------------------------------------- /src/assets/img/8BE31A06-4506-4265-B436-888B09223C51.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crifan/http_summary/5df18472b7caafb659e5c8665d320aea16654b70/src/assets/img/8BE31A06-4506-4265-B436-888B09223C51.png -------------------------------------------------------------------------------- /src/assets/img/9EED85A6-83B3-42DB-85D5-2B3B3E5F06A5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crifan/http_summary/5df18472b7caafb659e5c8665d320aea16654b70/src/assets/img/9EED85A6-83B3-42DB-85D5-2B3B3E5F06A5.png -------------------------------------------------------------------------------- /src/assets/img/B7221FAE-3275-4973-88BC-D4E79EB59875.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crifan/http_summary/5df18472b7caafb659e5c8665d320aea16654b70/src/assets/img/B7221FAE-3275-4973-88BC-D4E79EB59875.png -------------------------------------------------------------------------------- /src/assets/img/BD4592BC-6401-4D12-B84C-F50CFB53A3FB.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crifan/http_summary/5df18472b7caafb659e5c8665d320aea16654b70/src/assets/img/BD4592BC-6401-4D12-B84C-F50CFB53A3FB.png -------------------------------------------------------------------------------- /src/assets/img/D980D429-8ED2-4EAF-92A0-EC1AAD7E542B.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crifan/http_summary/5df18472b7caafb659e5c8665d320aea16654b70/src/assets/img/D980D429-8ED2-4EAF-92A0-EC1AAD7E542B.png -------------------------------------------------------------------------------- /src/assets/img/DB7AD0DA-1C42-4504-B8C5-D8DFCE4444A4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crifan/http_summary/5df18472b7caafb659e5c8665d320aea16654b70/src/assets/img/DB7AD0DA-1C42-4504-B8C5-D8DFCE4444A4.png -------------------------------------------------------------------------------- /src/assets/img/chrome_address_with_zhcn.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crifan/http_summary/5df18472b7caafb659e5c8665d320aea16654b70/src/assets/img/chrome_address_with_zhcn.png -------------------------------------------------------------------------------- /src/assets/img/http_lib_js_fetch_resp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crifan/http_summary/5df18472b7caafb659e5c8665d320aea16654b70/src/assets/img/http_lib_js_fetch_resp.png -------------------------------------------------------------------------------- /src/assets/img/http_range_download.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crifan/http_summary/5df18472b7caafb659e5c8665d320aea16654b70/src/assets/img/http_range_download.png -------------------------------------------------------------------------------- /src/assets/img/httpbin_get_resp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crifan/http_summary/5df18472b7caafb659e5c8665d320aea16654b70/src/assets/img/httpbin_get_resp.png -------------------------------------------------------------------------------- /src/assets/img/httpbin_ip_resp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crifan/http_summary/5df18472b7caafb659e5c8665d320aea16654b70/src/assets/img/httpbin_ip_resp.png -------------------------------------------------------------------------------- /src/assets/img/httpbin_json_format.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crifan/http_summary/5df18472b7caafb659e5c8665d320aea16654b70/src/assets/img/httpbin_json_format.png -------------------------------------------------------------------------------- /src/assets/img/httpbin_json_formatted.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crifan/http_summary/5df18472b7caafb659e5c8665d320aea16654b70/src/assets/img/httpbin_json_formatted.png -------------------------------------------------------------------------------- /src/assets/img/httpbin_org_home.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crifan/http_summary/5df18472b7caafb659e5c8665d320aea16654b70/src/assets/img/httpbin_org_home.png -------------------------------------------------------------------------------- /src/http_detail/README.md: -------------------------------------------------------------------------------- 1 | # HTTP详解 2 | 3 | 接下来详细解释HTTP的结构和组成。 4 | -------------------------------------------------------------------------------- /src/http_detail/ch1_http_structure.md: -------------------------------------------------------------------------------- 1 | # HTTP的典型结构 2 | 3 | 4 | 5 | ## Request 6 | - URL 7 | - Method 8 | - GET 9 | - 获取信息 10 | - 不会更改服务器内部的数据 11 | - POST 12 | - 向服务器发送数据: 13 | - 创建xxx 14 | - 更新xxx 15 | - 准确的说,其实应该用PUT或UPDATE 16 | - 会更改服务器内部的数据 17 | - PUT 18 | - PATCH 19 | - DELETE 20 | - HEAD:获取资源的元数据 21 | - OPTIONS:获取信息,关于资源的哪些属性是客户端可以改变的 22 | - Query Parameters 23 | - for `GET` 24 | - `query string`=`qs`=`query parameters`=`params`=`query component` 25 | - /xxx/xxx?key1=value1&key2=value2 26 | - for `POST` 27 | - body 28 | - JSON 29 | - url encoded 30 | - `key1=value1&key2=value2` 31 | - Headers 32 | - Content-Type 33 | - `application/json` 34 | - `application/json;charset=UTF-8` 35 | - Accept 36 | - `application/json` 37 | - Authorization 38 | - `Bearer 725a7c44b76c45ab95152bcee014ae6e_1` 39 | - Other 40 | - Cookie 41 | - LocalStorage 42 | - SessionStorage 43 | 44 | ## 响应Response 45 | 46 | - Status 47 | - Informational - 1xx 48 | - 100 CONTINUE 49 | - Successful - 2xx 50 | - 200 OK 51 | - Redirection - 3xx 52 | - 301 MOVED_PERMANENTLY 53 | - Client Error - 4xx 54 | - 400 BAD_REQUEST 55 | - 401 UNAUTHORIZED 56 | - 403 FORBIDDEN 57 | - 404 NOT_FOUND 58 | - Server Error - 5xx 59 | - 500 INTERNAL_SERVER_ERROR 60 | - Body 61 | - raw 62 | - to json 63 | - Other 64 | - Cookie 65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /src/http_detail/ch2_http_header.md: -------------------------------------------------------------------------------- 1 | # HTTP的Header头 2 | 3 | HTTP的Header包括两类: 4 | 5 | - 请求头=Request Header 6 | - 响应头=Response Header 7 | 8 | ## HTTP的Header方面的逻辑总结 9 | 10 | 既然是`Client问, Sever答`的过程,那么基本逻辑就是: 11 | 12 | * Client告诉服务器端,自己的Request请求,能够接受的各种信息是什么类型的 13 | * 所以Request中有很多Accept方面的请求头 14 | * Accept:能接受(返回)哪些类型 15 | * 格式:type/sub-type 16 | * \*/\* 表示任何类型 17 | * 举例: 18 | * Accept: application/json 19 | * Accept: text/plain 20 | * Accept: text/html 21 | * Accept: image/jpeg 22 | * Accept: application/msword 23 | * Accept: image/png 24 | * Accept: application/pdf 25 | * Accept-Charset 26 | * 能接受的字符集 27 | * Accept-Encoding 28 | * 能接受的(编码)压缩类型 29 | * 比如:gzip,deflate 30 | * Accept-Language 31 | * 能接受的语言类型 32 | * 以及其他一些额外的请求和希望 33 | * User-Agent:告诉你我是哪种浏览器(所处的操作系统是什么类型)等信息 34 | * 举例: 35 | * User-Agent:Mozilla/5.0 \(Windows; U; Windows NT 5.1; zh-CN;rv:1.8.1.14\) Gecko/20080404 Firefox/2.0.0.14 36 | * User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36 37 | * User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_1) AppleWebKit/604.3.5 (KHTML, like Gecko) Version/11.0.1 Safari/604.3.5 38 | * Referer:告诉服务器是从(参考)哪个链接去访问的 39 | * 举例:Referer: 40 | [https://www.google.co.uk/](https://www.google.co.uk/) 41 | * Keep-Alive:希望服务器保持此次连接(多长时间) 42 | * Cache-Control:表示是否使用缓存 43 | * Connection:完成本次请求的响应后,是否断开连接,是否要等待本次连接的后续请求了 44 | * Connection: close 45 | * Connection: keepalive 46 | * Sever返回响应,告诉客户端,自己的响应中数据都是什么类型的 47 | * 所以Response中有很多Content方面的字段,表示服务器返回的内容的各种类型说明 48 | * Content-Encoding:此响应中使用了什么压缩方法(gzip,deflate)压缩响应中的对象 49 | * 表示客户端的你用什么对应的方法去解压缩,才能得到数据的原文 50 | * 举例:Content-Encoding:gzip 51 | * Content-Language:用了什么语言 52 | * Content-Length:数据内容的长度,单位:字节 53 | * 举例:Content-Length: 2684 54 | * Content-Type:自己返回的数据是什么格式的 55 | * 和Request中的Accept对应 56 | * 举例:Content-Type:application/json 57 | * Connection:和Request对应 58 | * Connection: close 59 | * Connection: keepalive 60 | * 以及其他一些表示当前信息的情况的 61 | * Location:一个url地址,表示你想要的资源被转移到别处了, 62 | * 典型的是发生了302表示自动跳转,告诉你要的东西,换了地址了 63 | 64 | ## 常见Header举例 65 | 66 | * Request Header请求头 67 | * Accept 68 | * 代码调用API时: 69 | * Accept: application/json 70 | * Accept: application/json; charset=UTF-8 71 | * 浏览器访问网页时: 72 | * Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,_/_;q=0.8 73 | * Content-Type 74 | * 代码调用API时: 75 | * Content-Type:application/json 76 | * Content-Type:application/json; charset=UTF-8 77 | * Content-Type:application/x-www-form-urlencoded 78 | * Authorization 79 | * 代码调用API时: 80 | * Authorization: Bearer 6k8p8ucshobav531lftkb2f1bv 81 | * User-Agent 82 | * 浏览器访问网页时: 83 | * User-Agent: Mozilla/5.0\(Linux;X11\) 84 | * User-Agent: Mozilla/5.0 \(Macintosh; Intel Mac OS X 10\_13\_1\) AppleWebKit/537.36 \(KHTML, like Gecko\) Chrome/61.0.3163.100 Safari/537.36 85 | * Accept-Language 86 | * 浏览器访问网页时: 87 | * Accept-Language: zh-CN,zh;q=0.8,en;q=0.6 88 | * Accept-Encoding 89 | * 浏览器访问网页时: 90 | * Accept-Encoding: gzip, deflate, br 91 | * Response Header响应头 92 | * Content-Type 93 | * 代码调用API时: 94 | * Content-Type:application/json 95 | * 浏览器访问网页时: 96 | * Content-Type: text/html; charset=utf-8 97 | * Connection 98 | * 浏览器访问网页时: 99 | * Connection: Keep-Alive 100 | * Content-Encoding 101 | * 浏览器访问网页时: 102 | * Content-Encoding: gzip 103 | 104 | ## 更全更完整的Header 105 | 106 | ### Request的Header 107 | 108 | | Header | 解释 | 示例 | 109 | | :--- | :--- | :--- | 110 | | Accept | 指定客户端能够接收的内容类型 | Accept:text/plain,text/html | 111 | | Accept-Charset | 浏览器可以接受的字符编码集。 | Accept-Charset:iso-8859-5 | 112 | | Accept-Encoding | 指定浏览器可以支持的web服务器返回内容压缩编码类型。 | Accept-Encoding:compress,gzip | 113 | | Accept-Language | 浏览器可接受的语言 | Accept-Language:en,zh | 114 | | Accept-Ranges | 可以请求网页实体的一个或者多个子范围字段 | Accept-Ranges:bytes | 115 | | Authorization | HTTP授权的授权证书 | Authorization:Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ== | 116 | | Cache-Control | 指定请求和响应遵循的缓存机制 | Cache-Control:no-cache | 117 | | Connection | 表示是否需要持久连接。(HTTP 1.1默认进行持久连接) | Connection:close | 118 | | Cookie | HTTP请求发送时,会把保存在该请求域名下的所有cookie值一起发送给web服务器。 | Cookie:$Version=1;Skin=new; | 119 | | Content-Length | 请求的内容长度 | Content-Length:348 | 120 | | Content-Type | 请求的与实体对应的MIME信息 | Content-Type:application/x-www-form-urlencoded | 121 | | Date | 请求发送的日期和时间 | Date:Tue,15 Nov 2010 08:12:31 GMT | 122 | | Expect | 请求的特定的服务器行为 | Expect:100-continue | 123 | | From | 发出请求的用户的Email | From: user@email.com | 124 | | Host | 指定请求的服务器的域名和端口号 | Host: www.zcmhi.com | 125 | | If-Match | 只有请求内容与实体相匹配才有效 | If-Match:“737060cd8c284d8af7ad3082f209582d” | 126 | | If-Modified-Since | 如果请求的部分在指定时间之后被修改则请求成功,未被修改则返回304代码 | If-Modified-Since:Sat,29 Oct 2010 19:43:31 GMT | 127 | | If-None-Match | 如果内容未改变返回304代码,参数为服务器先前发送的Etag,与服务器回应的Etag比较判断是否改变 | If-None-Match:“737060cd8c284d8af7ad3082f209582d” | 128 | | If-Range | 如果实体未改变,服务器发送客户端丢失的部分,否则发送整个实体。参数也为Etag | If-Range:“737060cd8c284d8af7ad3082f209582d” | 129 | | If-Unmodified-Since | 只在实体在指定时间之后未被修改才请求成功 | If-Unmodified-Since:Sat,29 Oct 2010 19:43:31 GMT | 130 | | Max-Forwards | 限制信息通过代理和网关传送的时间 | Max-Forwards:10 | 131 | | Pragma | 用来包含实现特定的指令 | Pragma:no-cache | 132 | | Proxy-Authorization | 连接到代理的授权证书 | Proxy-Authorization:Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ== | 133 | | Range | 只请求实体的一部分,指定范围 | Range:bytes=500-999 | 134 | | Referer | 先前网页的地址,当前请求网页紧随其后,即来路 | Referer:http: | 135 | | TE | 客户端愿意接受的传输编码,并通知服务器接受接受尾加头信息 | TE:trailers,deflate;q=0.5 | 136 | | Upgrade | 向服务器指定某种传输协议以便服务器进行转换(如果支持) | Upgrade:HTTP/2.0,SHTTP/1.3,IRC/6.9,RTA/x11 | 137 | | User-Agent | User-Agent的内容包含发出请求的用户信息 | User-Agent:Mozilla/5.0\(Linux;X11\) | 138 | | Via | 通知中间网关或代理服务器地址,通信协议 | Via:1.0 fred,1.1 nowhere.com \(Apache/1.1\) | 139 | | Warning | 关于消息实体的警告信息 | Warn:199 Miscellaneous warning | 140 | 141 | ### Response的Header 142 | 143 | | Header | 解释 | 示例 | 144 | | :--- | :--- | :--- | 145 | | Accept-Ranges | 表明服务器是否支持指定范围请求及哪种类型的分段请求 | Accept-Ranges: bytes | 146 | | Age | 从原始服务器到代理缓存形成的估算时间(以秒计,非负) | Age: 12 | 147 | | Allow | 对某网络资源的有效的请求行为,不允许则返回405 | Allow: GET, HEAD | 148 | | Cache-Control | 告诉所有的缓存机制是否可以缓存及哪种类型 | Cache-Control: no-cache | 149 | | Content-Encoding | web服务器支持的返回内容压缩编码类型。 | Content-Encoding: gzip | 150 | | Content-Language | 响应体的语言 | Content-Language: en,zh | 151 | | Content-Length | 响应体的长度 | Content-Length: 348 | 152 | | Content-Location | 请求资源可替代的备用的另一地址 | Content-Location: /index.htm | 153 | | Content-MD5 | 返回资源的MD5校验值 | Content-MD5: Q2hlY2sgSW50ZWdyaXR5IQ== | 154 | | Content-Range | 在整个返回体中本部分的字节位置 | Content-Range: bytes 21010-47021/47022 | 155 | | Content-Type | 返回内容的MIME类型 | Content-Type: text/html; charset=utf-8 | 156 | | Date | 原始服务器消息发出的时间 | Date: Tue, 15 Nov 2010 08:12:31 GMT | 157 | | ETag | 请求变量的实体标签的当前值 | ETag: “737060cd8c284d8af7ad3082f209582d” | 158 | | Expires | 响应过期的日期和时间 | Expires: Thu, 01 Dec 2010 16:00:00 GMT | 159 | | Last-Modified | 请求资源的最后修改时间 | Last-Modified: Tue, 15 Nov 2010 12:45:26 GMT | 160 | | Location | 用来重定向接收方到非请求URL的位置来完成请求或标识新的资源 | Location:[http://www.zcmhi.com/archives/94.html](http://www.zcmhi.com/archives/94.html) | 161 | | Pragma | 包括实现特定的指令,它可应用到响应链上的任何接收方 | Pragma: no-cache | 162 | | Proxy-Authenticate | 它指出认证方案和可应用到代理的该URL上的参数 | Proxy-Authenticate: Basic | 163 | | refresh | 应用于重定向或一个新的资源被创造,在5秒之后重定向(由网景提出,被大部分浏览器支持) | Refresh: 5; url=[http://www.zcmhi.com/archives/94.html](http://www.zcmhi.com/archives/94.html) | 164 | | Retry-After | 如果实体暂时不可取,通知客户端在指定时间之后再次尝试 | Retry-After: 120 | 165 | | Server | web服务器软件名称 | Server: Apache/1.3.27 \(Unix\) \(Red-Hat/Linux\) | 166 | | Set-Cookie | 设置Http Cookie | Set-Cookie: UserID=JohnDoe; Max-Age=3600; Version=1 | 167 | | Trailer | 指出头域在分块传输编码的尾部存在 | Trailer: Max-Forwards | 168 | | Transfer-Encoding | 文件传输编码 | Transfer-Encoding:chunked | 169 | | Vary | 告诉下游代理是使用缓存响应还是从原始服务器请求 | Vary: \* | 170 | | Via | 告知代理客户端响应是通过哪里发送的 | Via: 1.0 fred, 1.1 nowhere.com \(Apache/1.1\) | 171 | | Warning | 警告实体可能存在的问题 | Warning: 199 Miscellaneous warning | 172 | | WWW-Authenticate | 表明客户端请求实体应该使用的授权方案 | WWW-Authenticate: Basic | 173 | 174 | 175 | -------------------------------------------------------------------------------- /src/http_detail/ch3_http_req_param_encode.md: -------------------------------------------------------------------------------- 1 | # HTTP的请求参数和参数编码 2 | 3 | 下面介绍HTTP的请求参数`Request Parameters`和请求参数的编码`Request Parameters Encoding` 4 | 5 | ## GET的请求的参数:`query string` 6 | 7 | 关于Http的GET的请求参数,也有别的叫法: 8 | 9 | * `请求参数`=`request parameter` 10 | * = `查询`=`query` 11 | * = `查询字符串`=`query string` 12 | * = `请求参数`=`request parameters` 13 | * = `参数序列化`=`param serialization`=`parameter serialization` 14 | 15 | 转换后放到Url中的,是如下形式: 16 | 17 | `?key1=value1` 18 | 19 | `?key1=value1&key2=value2` 20 | 21 | 22 | 典型的是: 23 | 24 | GET:参数想要放在url中以`?key1=value1&key2=value2`的形式 25 | 26 | 则有两种做法: 27 | 28 | * 自己把参数组合成对应的格式,放到url中 29 | * 把参数(字典,对象等)调用url encode函数去编码,生成对应的格式(再放到url中) 30 | 31 | > [!NOTE|title:GET的一般特点] 32 | > * GET 请求有长度限制 33 | > * 所以query string一般被限制在1024个字节 34 | > * 超过限制则后台无法解析参数 35 | > * GET 请求可被缓存 36 | > * GET 请求保留在浏览器历史记录中 37 | > * GET 请求可被收藏为书签 38 | > * GET 请求不应在处理敏感数据时使用 39 | > * GET 请求只应当用于取回数据 40 | 41 | ### 处理查询参数的库 42 | 43 | #### JS的qs 44 | 45 | * js中http网络库:axios 46 | * 其中有,处理查询参数的:`qs` 47 | * https://www.npmjs.com/package/qs 48 | * 当需要处理get的query string时,就可以利用其中的Qs子库去处理 49 | ```js 50 | Qs.stringify(data) 51 | ``` 52 | * 实现:把(一般是字典类型==JSON类型的)变量,转换,字符串换,序列化,为`&key1=value1`之类的形式 53 | 54 | 关于别名:`参数序列化` 55 | 56 | 其中官网demo中: 57 | 58 | ```js 59 | // `paramsSerializer` is an optional function in charge of serializing `params` 60 | // (e.g. https://www.npmjs.com/package/qs, http://api.jquery.com/jquery.param/) 61 | paramsSerializer: function(params) { 62 | return Qs.stringify(params, {arrayFormat: 'brackets'}) 63 | }, 64 | ``` 65 | 66 | 也说明了: 67 | 68 | 此处的`stringify`=`字符串化`,也叫做:`paramsSerializer`=``参数序列化` 69 | 70 | 71 | 举例: 72 | 73 | 某js项目中用到了`stringify`: 74 | 75 | ```js 76 | import { stringify } from 'qs'; 77 | 78 | export async function queryRule(params) { 79 | return request(`/api/rule?${stringify(params)}`); 80 | } 81 | ``` 82 | 83 | ## POST的请求的参数:`post body` 84 | 85 | 典型的是:把一堆的参数,放到`post`的`body`中,格式一般都是`json`格式 86 | 87 | 则一般也有两种做法: 88 | 89 | * 自己把参数(对象,字典等),转换为对应的json字符串 90 | * 调用库提供的方法去encode你的参数对象为json 91 | 92 | 其他一些解释: 93 | > [!NOTE|title:POST的一般特点] 94 | > * POST 请求不会被缓存 95 | > * POST 请求不会保留在浏览器历史记录中 96 | > * POST 不能被收藏为书签 97 | > * POST 请求对数据长度没有要求 98 | 99 | ## GET和POST的请求的参数的编码 100 | 101 | 举例: 102 | 103 | ### http库axios中create时支持的config中的paramsSerializer 104 | 105 | 就支持利用其他序列化的库,比如: 106 | 107 | * Javascript中的: 108 | * qs库 109 | * [https://www.npmjs.com/package/qs](https://www.npmjs.com/package/qs) 110 | * 举例: 111 | * `Qs.stringify(params, {arrayFormat: 'brackets'})` 112 | 113 | ### Alamofire中,对于get的参数支持url encoding,对于post支持json encoding 114 | 115 | 所以代码可以写成: 116 | 117 | ```swift 118 | var paramEncoding:ParameterEncoding = JSONEncoding.default 119 | if (httpMethod == .get) { 120 | paramEncoding = URLEncoding.default 121 | } 122 | 123 | let curHttpReq = Alamofire.request(url, method: httpMethod, parameters: parameters, encoding: paramEncoding, headers: curHeaders) 124 | ``` 125 | 126 | ![](../assets/img/2B2421A4-B01C-49BA-B49F-607CD2E7A6C2.png) 127 | 128 | 然后从外部调用时,对于get的url参数,可以直接传递: 129 | 130 | get中的url的参数的对象,让Alamofire内部去利用URLEncoding转换为对应的?key1=value1&key2=value2的格式: 131 | 132 | ```swift 133 | var parameters = [String : AnyObject]() 134 | parameters = [ 135 | "planId":self.visitId as AnyObject, 136 | "name":self.missionInfo.missionInfo.name as AnyObject, 137 | "pics":pics as AnyObject, 138 | "publisher":gCurUserItem.userInfo.pkEmpno as AnyObject, 139 | "resultDescription":self.missionInfo.missionInfo.resultDescription as AnyObject, 140 | "finish":finishInt as AnyObject, 141 | "planProblem":planProblem as AnyObject 142 | ] 143 | 144 | getUrlRespJson_async( 145 | httpMethod: hTTPMethod, 146 | url: url, 147 | parameters: parameters, 148 | respJsonHandle: { [weak self] (response) in 149 | ``` 150 | 151 | ![](../assets/img/0450D66D-6641-403F-BF7F-ED9496AD4A30.png) 152 | 153 | 另外,对应的对于POST来说,把json对象转换为json字符串的例子: 154 | 155 | ```swift 156 | let parameters = [ 157 | "id":self.missionInfo.missionProblem.id as AnyObject, 158 | "checkPlanId":self.checkPlanId as AnyObject, 159 | "checkResult":self.resultCell.textview.text as AnyObject, 160 | "pass":self.pass as AnyObject , 161 | 162 | ] as [String : AnyObject]? 163 | 164 | getUrlRespJson_async( 165 | httpMethod: .post, 166 | url: ServerApi.getProblemIdResult(visitId: self.visitId,problemId: self.missionInfo.missionProblem.id), 167 | parameters: parameters , 168 | respJsonHandle: { [weak self] (response) in 169 | ``` 170 | 171 | ![](../assets/img/7C86AF70-EADF-4E11-A766-12467A62C778.png) 172 | 则内部的Alamofire就会把该参数对象,通过JSONEncoding转换为json字符串了。 173 | 174 | 举例: 175 | python中,get中url参数可以利用`urllib.urlencode`(或`urllib.quote_plus`)去把dict字典转换为key=value的形式: 176 | 177 | ```python 178 | import urllib 179 | params = urllib.urlencode({'spam': 1, 'eggs': 2, 'bacon': 0}) 180 | url = "http://www.musi-cal.com/cgi-bin/query?%s"; % params 181 | ``` 182 | 183 | ## 关于HTTP参数编码的常见场景和问题 184 | 185 | ### 空格应该被encode编码为`+`还是`%20`? 186 | 187 | 如果你接触Python的url的encode比较多,可能会注意到一个现象: 188 | 189 | 好像空格有时候被编码为+,有时候被编码为%20,到底哪个才对? 190 | 191 | Percent Encode也被叫做URL Encode 192 | Percent Encode指的是,一些字符,在被(url)encode后,往往都是变成%xx 193 | 比如: 194 | 内部对应着HTTP请求时,类型被设置为:`application/x-www-form-urlencoded` 195 | 196 | 表格太长,分两个 197 | 198 | | [!](https://en.wikipedia.org/wiki/Exclamation_mark) | [\#](https://en.wikipedia.org/wiki/Number_sign) | [$](https://en.wikipedia.org/wiki/Dollar_sign) | [&](https://en.wikipedia.org/wiki/Ampersand) | ['](https://en.wikipedia.org/wiki/Apostrophe_%28mark%29) | [\(](https://en.wikipedia.org/wiki/Parenthesis) | [\)](https://en.wikipedia.org/wiki/Parenthesis) | [\*](https://en.wikipedia.org/wiki/Asterisk) | [+](https://en.wikipedia.org/wiki/Plus_sign) | 199 | | :--- | :--- | :--- | :--- | :--- | :--- | :--- | :--- | :--- | 200 | | %21 | %23 | %24 | %26 | %27 | %28 | %29 | %2A | %2B | 201 | 202 | 和: 203 | 204 | | [,](https://en.wikipedia.org/wiki/Comma) | [/](https://en.wikipedia.org/wiki/Slash_%28punctuation%29) | [:](https://en.wikipedia.org/wiki/Colon_%28punctuation%29) | [;](https://en.wikipedia.org/wiki/Semicolon) | [=](https://en.wikipedia.org/wiki/Equal_sign) | [?](https://en.wikipedia.org/wiki/Question_mark) | [@](https://en.wikipedia.org/wiki/@) | [[](https://en.wikipedia.org/wiki/Square_bracket) | [\]](https://en.wikipedia.org/wiki/Square_bracket) | 205 | | :--- | :--- | :--- | :--- | :--- | :--- | :--- | :--- | :--- | 206 | | %2C | %2F | %3A | %3B | %3D | %3F | %40 | %5B | %5D | 207 | 208 | 而其他常见的字符被编码后的效果是: 209 | 210 | | [newline](https://en.wikipedia.org/wiki/Newline) | [space](https://en.wikipedia.org/wiki/Space_%28punctuation%29) | ["](https://en.wikipedia.org/wiki/Double_quote) | [%](https://en.wikipedia.org/wiki/Percent_sign) | [-](https://en.wikipedia.org/wiki/Hyphen) | [.](https://en.wikipedia.org/wiki/Full_stop) | [<](https://en.wikipedia.org/wiki/Angle_bracket) | [>](https://en.wikipedia.org/wiki/Angle_bracket) | 211 | | :--- | :--- | :--- | :--- | :--- | :--- | :--- | :--- | 212 | | %0A or %0D or %0D%0A | %20 | %22 | %25 | %2D | %2E | %3C | %3E | 213 | 和 214 | 215 | | [\](https://en.wikipedia.org/wiki/Back_slash) | [^](https://en.wikipedia.org/wiki/Caret) | [\_](https://en.wikipedia.org/wiki/Underscore) | [\`](https://en.wikipedia.org/wiki/Grave_accent) | [{](https://en.wikipedia.org/wiki/Curly_bracket) | [|](https://en.wikipedia.org/wiki/Vertical_bar) | [}](https://en.wikipedia.org/wiki/Curly_bracket) | [~](https://en.wikipedia.org/wiki/Tilde) | 216 | | :--- | :--- | :--- | :--- | :--- | :--- | :--- | :--- | 217 | | %5C | %5E | %5F | %60 | %7B | %7C | %7D | %7E | 218 | 219 | 即: 220 | 221 | 空格正常情况下被url encode=percent encode,的结果是%20 222 | 223 | 但是之所以有时候会看到+是因为: 224 | 225 | 历史上,最早的网页技术中,在表单form被(通过HTTP的GET/POST等请求,或者是邮件发送)提交时,键key和值value,都是被percent encode=url encode的 226 | 227 | 对应着类型是:`application/x-www-form-urlencoded` 228 | 229 | 但是后来有些变种的处理,其中就包括把空格space编码为+(而不是%20) 230 | 231 | > [!TIP|title:空格被编码的逻辑的历史] 232 | > * 空格被url encode=percent encode,应该是:**%20** 233 | > * 而之前历史上有些变种的处理,会编码为:**+** 234 | 235 | 而Python中对于url encode相关的函数有3种,对应的效果分别如下: 236 | 237 | ```python 238 | #!/usr/bin/python 239 | # -*- coding: utf-8 -*- 240 | 241 | import urllib 242 | 243 | paraValue = "Crifan Li" 244 | queryPara = { "name" : paraValue } 245 | urlEncodedQueryPara = urllib.urlencode(queryPara) 246 | print "urlEncodedQueryPara=%s"%(urlEncodedQueryPara) # urlEncodedQueryPara=name=Crifan+Li 247 | quotedValue = urllib.quote(paraValue) # quotedValue=Crifan%20Li 248 | quotedPlusValue = urllib.quote_plus(paraValue) # quotedPlusValue=Crifan+Li 249 | print "quotedValue=%s,quotedPlusValue=%s"%(quotedValue, quotedPlusValue) 250 | ``` 251 | 252 | > [!TIP|title:空格被编码] 253 | > * `urllib.urlencode`编码(字典中的)value 254 | > * `urllib.quote_plus`编码字符串:空格编码为**+** 255 | > * `urllib.quote`编码字符串:空格编码为**%20** 256 | 257 | ### 在url地址里包含中文时的编码显示和内部逻辑 258 | 259 | 背景: 260 | 如果url地址中有非普通的ASCII字符串,理论上都是会被编码后,所以你看到的如果url地址中有中文,实际上打开都是%xx之类的地址 261 | 中文字符串和其他字符串编码逻辑是一样的。 262 | 263 | 对于中文类字符被url encode,有很多在线网站可以帮你实现,比如: 264 | 265 | * `http://tool.chinaz.com/tools/urlencode.aspx` 266 | * `http://tool.oschina.net/encode?type=4` 267 | 268 | 输入中文**李茂**就可以被(UTF-8)编码为:`%e6%9d%8e%e8%8c%82` 269 | 270 | 271 | ![](../assets/img/665389BA-F1E4-4A17-B2FF-BEF7E773DD8D.png) 272 | ![](../assets/img/D980D429-8ED2-4EAF-92A0-EC1AAD7E542B.png) 273 | 274 | > [!TIP|title:提示] 275 | > * 一般网页地址中的字符编码都用的是UTF-8 276 | > * 上面编码也都是采用的UTF-8编码得到的结果 277 | 278 | 而如果想要换成别的编码,比如另一种常见的中文编码GB2312,则编码出来的是另外的结果: 279 | ![](../assets/img/61CD3BDE-03EF-48A8-811E-DE5572656473.png) 280 | 281 | > [!TIP|title:同样字符串的不同编码的效果] 282 | > * 李茂 -》 `UTF-8`编码后 -》`%e6%9d%8e%e8%8c%82` 283 | > * 李茂 -》 `GB2312`编码后 -》 `%c0%ee%c3%af` 284 | 285 | ### 为何浏览器中的地址栏中的url地址可以看到有中文,而不是url encode之后的%xx? 286 | 287 | 而你在浏览器中看到的中文地址其实是浏览器帮你解码后的中文 288 | 真正的url地址是%xx形式的被(UTF-8)编码后的地址 289 | 比如你在Chrome(或其他浏览器)中看到的地址中有中文: 290 | `https://github.com/imaidev/imaidev.github.io/wiki/wifi嗅探与客流统计` 291 | 292 | ![](../assets/img/chrome_address_with_zhcn.png) 293 | 294 | 实际上内部真正的地址是: 295 | 296 | [https://github.com/imaidev/imaidev.github.io/wiki/wifi%E5%97%85%E6%8E%A2%E4%B8%8E%E5%AE%A2%E6%B5%81%E7%BB%9F%E8%AE%A1](https://github.com/imaidev/imaidev.github.io/wiki/wifi嗅探与客流统计) 297 | 298 | -》你可以通过,在地址栏中右键-》复制 299 | ![](../assets/img/8BE31A06-4506-4265-B436-888B09223C51.png) 300 | 再粘贴到别的文本工具中,而得到看到真正的被编码后的地址: 301 | ![](../assets/img/644015DB-FDF6-48F8-AB2C-E68C76C63AD8.png) 302 | 类似的,把该地址去(利用前面说的在线网站帮忙)解码也可以得到同样的中文: 303 | 304 | [http://tool.oschina.net/encode?type=4](http://tool.oschina.net/encode?type=4) 305 | ![](../assets/img/0E984231-A46A-49DA-AB4C-8B1B6859BCE2.png) 306 | 307 | -------------------------------------------------------------------------------- /src/http_detail/ch4_http_resp_status_code.md: -------------------------------------------------------------------------------- 1 | # HTTP的响应的状态码 2 | 3 | `Http状态码`=`HTTP Code` 4 | 5 | 关于状态码的类别的含义的总体解释是: 6 | 7 | | 状态码大类 | 表示的含义 | 客户端client要做的事 | 服务器端server要做的事 | 8 | | :--- | :--- | :--- | :--- | 9 | | 1xx | Informational 信息 | 啥都不用做,知道就好 | 告诉client,信息收到了,我后续会处理 | 10 | | 2xx | Successful 成功 | 啥都不用做,知道就好 | 告诉client,请求已正确处理 | 11 | | 3xx | Redirection 重定向 | 重新请求返回的新地址 -> 才能获取真正需要的数据 | 告诉client,你需要的内容,由于一些原因,比如地址已发生变化了,然后返回该内容的新地址 | 12 | | 4xx | Client Error 客户端的错误 | 确保用正确的参数和信息正确,重新请求 | 告诉client,请求已正确处理 | 13 | | 5xx | Server Error 服务器端的错误 | (一般来说)都无需啥操作 -> 往往需要服务器端改了bug后,重新发送请求 | 需要服务器Server端自己找到具体出了啥错 -> 往往是服务器端的代码的bug导致了出错 | 14 | 15 | ## 最常用的状态码及含义 16 | 17 | * Successful - 2xx:成功类,行为被成功地接受、理解和采纳 18 | * `200`=`OK` 19 | * 服务器成功返回用户请求的数据 20 | * 注意:(部分人)为了简化处理,`POST`创建成功后应该返回`201`的但也返回`200` 21 | * `400`=`BAD REQUEST` 22 | * 错误的请求 23 | * 注意:(部分人)往往为了简化处理,把属于`401`的`没有权限`和属于`403`的`有权限但是权限不够`,往往都返回`404` 24 | * `404`=`NOT FOUND` 25 | * 找不到资源 26 | * 注意:有些做法是,把属于`401`或`403`的原因,假装找不到而返回`404` 27 | * `500`=`INTERNAL SERVER ERROR` 28 | * 服务器内部错误 29 | * 最常见的原因是:服务器内部挂了 30 | * 比如:你传递参数中有些参数是空,而导致后台代码无法解析,出现异常而崩溃 31 | 32 | ## 次常用的响应码及含义 33 | 34 | * Informational - 1xx:信息类,请求收到,继续处理 35 | * Successful - 2xx:成功类,行为被成功地接受、理解和采纳 36 | * 201 CREATED 37 | * 通过POST或PUT创建资源成功 38 | * 通过response header中会返回新创建的资源的url连接 39 | * response body可能有信息,也可能为空 40 | * 202 Accepted 41 | * 服务器接受了此请求,但是待会才会执行 42 | * 204 NO CONTENT 43 | * 资源创建成功,但是没有返回内容 44 | * 常用于DELETE或PUT操作的返回 45 | * Redirection - 3xx:重定向类,为了完成请求,必须进一步执行的动作 46 | * 301 Moved 47 | * 该资源的URI接口已经变了,变成别的接口了 48 | * response header中应该告诉新接口地址,比如: 49 | * URI: url地址 50 | * Client Error - 4xx:客户端错误类,请求包含语法错误或者请求无法实现 51 | * 401 UNAUTHORIZED 52 | * 没有权限访问该资源 53 | * 典型情况:用户没有登录,没有获得对应的access token而直接访问某资源 54 | * 403 FORBIDDEN 55 | * 禁止访问 56 | * 典型情况:虽然用户已登录,但是去更新/删除需要更高权限才能操作的资源 57 | * 405 METHOD NOT ALLOWED 58 | * 方法不允许 59 | * 举例:比如某个资源不允许PATCH操作,但是你调用PATCH操作 60 | * 406 - Not Acceptable 61 | * 无效的请求 62 | * 比如:请求中的部分参数是无效的 63 | * 409 CONFLICT 64 | * 有冲突 65 | * 举例:新建一个用户,但是主键手机号和之前已有用户冲突 66 | * 415 Unsupported Media Type 67 | * 典型情况:请求的header有问题 68 | * 422 Unprocessable Entity 69 | * Specify values for all required parameter fields 70 | * Server Error - 5xx:服务器错误类,服务器不能实现一种明显无效的请求 71 | * 502 BAD GATEWAY 72 | * 网管错误 73 | * 503 SERVICE UNAVAILABLE 74 | * 无服务 75 | * 举例:比如服务器内部正在维护,暂时不提供服务。可以换个时间重试 76 | -------------------------------------------------------------------------------- /src/http_detail/ch5_http_resp_data_format_json.md: -------------------------------------------------------------------------------- 1 | # HTTP的响应数据格式JSON 2 | 3 | 调用服务器API接口,常见返回内容格式是:`JSON` 4 | 5 | http的response返回的内容,原始raw格式,都是字符串string,text的类型 6 | 7 | 如果想要把raw的text/string转换为json,则可以: 8 | 9 | 利用很多库自带的功能,把返回内容转换为JSON 10 | ## iOS的Alamofire 11 | ```swift 12 | Alamofire.request("https://httpbin.org/get").responseJSON { response in 13 | if let json = response.result.value { 14 | print("JSON: \(json)") // serialized json response 15 | } 16 | } 17 | ``` 18 | ## Python的Requests 19 | ```python 20 | >>> r = requests.get('https://api.github.com/user', auth=('user', 'pass')) 21 | >>> r.status_code 22 | 200 23 | >>> r.headers['content-type'] 24 | 'application/json; charset=utf8' 25 | >>> r.encoding 26 | 'utf-8' 27 | >>> r.text 28 | u'{"type":"User"...' 29 | >>> r.json() 30 | {u'disk_usage': 368627, u'private_gists': 484, ...} 31 | ``` 32 | -------------------------------------------------------------------------------- /src/http_intro/README.md: -------------------------------------------------------------------------------- 1 | # HTTP简介 2 | 3 | 接下来先简要介绍一下HTTP的基础知识。 4 | -------------------------------------------------------------------------------- /src/http_intro/ch1_http_learn_purpose.md: -------------------------------------------------------------------------------- 1 | # HTTP学习目的 2 | 3 | 写此HTTP相关内容的教程,期望能对不同类型的人员达到不同的目标: 4 | 5 | - **普通用户**用浏览器上网 6 | - 了解打开网址到页面显示背后的故事 7 | - \(iOS/Android\)**移动端开发** 8 | - 了解用代码调用后台API接口时 9 | - 知道HTTP的有哪些方法,GET/POST等,知道其大概用途 10 | - 如何传递GET和POST时候的参数 11 | - GET时的`query string` 12 | - POST时的body的json 13 | - 学习用`Postman`等工具去测试后台提供的接口 14 | - **后台人员**设计API接口 15 | - 如何设计一个`RESTful`的API 16 | - 减少不良风格的接口 17 | - 比如:/getUser, /updateUser 18 | - 学习用Postman等工具去测试自己写的API接口 19 | - 学习如何用Postman等工具去生成API文档 20 | - **测试人员** 21 | - 充分利用Postman等工具去实现接口的自动化测试 22 | 23 | 24 | -------------------------------------------------------------------------------- /src/http_intro/ch2_http_intro.md: -------------------------------------------------------------------------------- 1 | # HTTP简介 2 | 3 | `HTTP`=`Hyper Text Transfer Protocol`=`超文本传输协议` 4 | 5 | HTTP的总体思路是: 6 | 7 | - 客户端:向服务器发送一个`请求`=`Request`,请求头包含请求的方法、URI、协议版本、以及包含请求修饰符、客户信息和内容的类似于MIME的消息结构。 8 | - `服务器`:以一个状态行作出`响应`=`Response`,相应的内容包括消息协议的版本,成功或者错误编码加上包含服务器信息、实体元信息以及可能的实体内容。 9 | 10 | 简而言之就是一个你问我答的协议: 11 | - 客户端Client 问=`请求`=`Request` 12 | - 服务器Server 答=`响应`=`Response` 13 | 14 | 关于HTTP的相关的详细知识,或许很多人不是很熟悉。 15 | 但是: 16 | - 作为普通电脑用户的你,经常用`浏览器`(`IE`/`Chrome`/`Firefox`等)去浏览网页时 17 | - 作为程序开发,用网络库去调用服务器后台提供的接口时 18 | 其实内部都用到了HTTP的技术。 19 | 20 | 21 | 比如一些典型情况: 22 | 23 | ## 普通用户用浏览器去查看网页 24 | 25 | 比如用户在用浏览器去打开网址: 26 | 27 | http://www.baidu.com 28 | 29 | 去查看网页内容: 30 | 31 | ![打开百度页面](../assets/img/2D3C5583-DE77-4BA8-A128-FCC1218B5FA8.png) 32 | 33 | ## 程序员写代码去调用后台接口 34 | 35 | 比如 (卓越一线的iOS的)swift代码中利用`Alamofire`的HTTP网络库,去实现: 36 | 37 | 传递用户名ID+密码的参数和POST类型,调用Alamofire发送请求,完成用户的登录 38 | 39 | ![](../assets/img/2F0FA94A-462F-49D5-8249-D7BFAE34CB76.png) 40 | 41 | ![](../assets/img/446072B2-ECCA-4D32-88C4-91CE64F85605.png) 42 | 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /src/http_intro/ch3_http_internal_process.md: -------------------------------------------------------------------------------- 1 | # HTTP内部流程 2 | 其实内部都是通用的HTTP的逻辑: 3 | - 发送HTTP的请求 4 | - 接受到响应后 5 | - 解析并显示出对应的内容 6 | - 解析得到所需要的数据 7 | 8 | 那如何才能看到内部的HTTP的请求和响应到底是什么样的呢? 9 | 有很多方式可以实现查看内部到底发送了什么样的HTTP请求,和接收到了什么样的响应: 10 | - 对于浏览器访问网页 11 | - 可以用`Chrome`/`Safari`/`Firefox`等浏览器自带的调试工具:`开发者工具` 12 | - 可以用其他工具去模拟 13 | - 比如:命令行工具`curl` 14 | - 对于写代码调用后台接口 15 | - 可以用postman去模拟和查看 16 | 17 | 下面详细介绍如何查看内部的具体流程: 18 | 19 | ## 用Chrome的开发者工具去查看 20 | 先去打开: 21 | 右上角 三个点-》更多工具-》开发者工具 22 | ![](../assets/img/9EED85A6-83B3-42DB-85D5-2B3B3E5F06A5.png) 23 | 24 | 点击到Network列,然后再去访问地址 www.baidu.com 25 | 26 | 就可以看到会有一堆的内容列出来,点击第一个 www.baidu.com 的Header 27 | 28 | 即可看到,对应的Request和Response的信息: 29 | 30 | ![](../assets/img/681BB8D6-73BC-4EAD-804E-4014E5C12299.png) 31 | 32 | 通过点击Request Headers和Response Headers的view source可以看到未被解析之前的原始内容: 33 | ![](../assets/img/B7221FAE-3275-4973-88BC-D4E79EB59875.png) 34 | ![](../assets/img/58E15E6F-F862-4DFA-B248-EA981AB89FE6.png) 35 | 36 | 对应的原始内容为: 37 | 38 | Request请求: 39 | ```bash 40 | GET / HTTP/1.1 41 | Host: www.baidu.com 42 | Connection: keep-alive 43 | Cache-Control: max-age=0 44 | User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36 45 | Upgrade-Insecure-Requests: 1 46 | Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8 47 | Accept-Encoding: gzip, deflate, br 48 | Accept-Language: zh-CN,zh;q=0.8,en;q=0.6 49 | Cookie: BAIDUID=6720BF4EAED8C8448EB6540DAF83BE56:FG=1; BIDUPSID=6720BF4EAED8C8448EB6540DAF83BE56; PSTM=1449798993; MCITY=-224%3A; BD_CK_SAM=1; PSINO=3; BD_HOME=0; H_PS_PSSID=1430_24568_21116_24880_20929; BD_UPN=123253 50 | ``` 51 | 52 | Response响应: 53 | ```bash 54 | HTTP/1.1 200 OK 55 | Bdpagetype: 1 56 | Bdqid: 0xd4bdc47c00000909 57 | Bduserid: 0 58 | Cache-Control: private 59 | Connection: Keep-Alive 60 | Content-Encoding: gzip 61 | Content-Type: text/html; charset=utf-8 62 | Cxy_all: baidu+1ea6be4d211f802306f9e10940507eba 63 | Date: Mon, 13 Nov 2017 01:32:41 GMT 64 | Expires: Mon, 13 Nov 2017 01:32:06 GMT 65 | Server: BWS/1.1 66 | Set-Cookie: BDSVRTM=0; path=/ 67 | Set-Cookie: BD_HOME=0; path=/ 68 | Set-Cookie: H_PS_PSSID=1430_24568_21116_24880_20929; path=/; domain=.baidu.com 69 | Strict-Transport-Security: max-age=172800 70 | Vary: Accept-Encoding 71 | X-Powered-By: HPHP 72 | X-Ua-Compatible: IE=Edge,chrome=1 73 | Transfer-Encoding: chunked 74 | ``` 75 | ## 用curl工具去模拟浏览器访问百度的过程 76 | 77 | 在命令行中输入: 78 | ```bash 79 | curl -v www.baidu.com 80 | ``` 81 | 返回的结果是: 82 | ```bash 83 | ➜ ~ curl -v www.baidu.com 84 | * Rebuilt URL to: www.baidu.com/ 85 | * Trying 180.97.33.107... 86 | * TCP_NODELAY set 87 | * Connected to www.baidu.com (180.97.33.107) port 80 (#0) 88 | > GET / HTTP/1.1 89 | > Host: www.baidu.com 90 | > User-Agent: curl/7.54.0 91 | > Accept: */* 92 | > 93 | < HTTP/1.1 200 OK 94 | < Server: bfe/1.0.8.18 95 | < Date: Mon, 13 Nov 2017 01:35:55 GMT 96 | < Content-Type: text/html 97 | < Content-Length: 2381 98 | < Last-Modified: Mon, 23 Jan 2017 13:28:24 GMT 99 | < Connection: Keep-Alive 100 | < ETag: "588604f8-94d" 101 | < Cache-Control: private, no-cache, no-store, proxy-revalidate, no-transform 102 | < Pragma: no-cache 103 | < Set-Cookie: BDORZ=27315; max-age=86400; domain=.baidu.com; path=/ 104 | < Accept-Ranges: bytes 105 | < 106 | 107 | 百度一下,你就知道;
108 | * Connection #0 to host www.baidu.com left intact 109 | ``` 110 | 111 | ![](../assets/img/1D928B86-A1C2-404B-A682-48332C1F71DF.png) 112 | 113 | ## 用`postman`去模拟前面的调用后台接口的登录过程 114 | ![](../assets/img/4ACF224B-4768-406B-B28D-50F8131C38C4.png) 115 | 116 | 其中内部发送的HTTP请求,可以通过Code查看: 117 | ![](../assets/img/523C7AA5-AF8F-477A-A7CF-BA415AC37F8F.png) 118 | 119 | ```bash 120 | POST /v1/skr/login HTTP/1.1 121 | Host: 123.206.101.36:9090 122 | Content-Type: application/json; charset=UTF-8 123 | authorization: Bearer mum5emp17q28st6v36ajltfvf3 124 | Cache-Control: no-cache 125 | Postman-Token: deb6784d-3689-32ce-ac01-687c22ad1b6e 126 | 127 | { 128 | "user" : "13429", 129 | "password" : "666666" 130 | } 131 | ``` 132 | 133 | 134 | -------------------------------------------------------------------------------- /src/http_intro/ch4_http_basic_logic.md: -------------------------------------------------------------------------------- 1 | # HTTP基本逻辑总结 2 | 上述的所有用浏览器访问网页,用代码调用后台接口去登录等等,其内部的HTTP的基本逻辑和核心流程都是一样的: 3 | ## (客户端)发送请求Request 4 | HTTP协议规定request的格式: 5 | ![](../assets/img/DB7AD0DA-1C42-4504-B8C5-D8DFCE4444A4.png) 6 | 7 | 此处: 8 | ```bash 9 | GET / HTTP/1.1 10 | ... 11 | User-Agent: curl/7.54.0 12 | Accept: */* 13 | ``` 14 | 其中: 15 | - `GET`:方法类型,HTTP/1.1表示HTTP协议的版本是1.1 16 | - 使用第三方库时,也需要制定对应的GET/POST/。。。 17 | - 现在多数的HTTP协议都是使用的1.1 18 | - `User-Agent`:用户代理,表示自己的客户端的类型是curl 19 | - 使用第三方库时,一般不需要设置此参数 20 | - 第三方库会自动帮你设置 21 | - 如果是浏览器的话,不同浏览器对应不同的预设值 22 | - 比如上面的Chrome此处是: 23 | - User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36 24 | - `Accept`:声明自己接收的信息的类型为*/*,表示所有类型内容都运行 25 | - 如果调用服务器接口时,往往设置为:application/json 26 | 27 | ## 获得(服务器返回的)响应Response 28 | HTTP协议规定的响应的格式: 29 | ![](../assets/img/4DDE8C10-6593-4BFD-8BBC-A15A79698C25.png) 30 | 31 | 举例: 32 | ![](../assets/img/8495B70C-58BC-4786-940A-FC5834B12343.jpg) 33 | 34 | 此处的: 35 | 36 | ```bash 37 | < HTTP/1.1 200 OK 38 | 。。。 39 | < Content-Type: text/html 40 | < Content-Length: 2381 41 | 。。。。 42 | < 43 | 44 | ........ 45 | * Connection #0 to host www.baidu.com left intact 46 | ``` 47 | 其中: 48 | - HTTP/1.1 200 OK:表示1.1版本的HTTP协议,返回状态为200,表示正常 49 | - 其他典型的,不正常的,有问题的状态有很多,比如404找不到,500服务器内部错误等等 50 | - Content-Type: text/html:内容的类型为html 51 | - Content-Length: 2381:内容的长度为2381字节 52 | - ...:html的内容,浏览器加载此内容后,即可显示出你所看到的网页 53 | -------------------------------------------------------------------------------- /src/http_related/README.md: -------------------------------------------------------------------------------- 1 | # HTTP相关 2 | 3 | 接下来介绍HTTP相关的一些心得,工具,后台API设计等内容。 4 | 5 | -------------------------------------------------------------------------------- /src/http_related/ch2_http_api_design.md: -------------------------------------------------------------------------------- 1 | # HTTP的后台API设计 2 | 3 | ## HTTP的后台API设计常用规范:`RESTful` 4 | 5 | 关于`RESTful`,详见另外的教程:[HTTP后台端:RESTful API接口设计](http://book.crifan.com/books/http_restful_api/website/) 6 | 7 | ## 后台设计时记得要支持`CORS` 8 | 9 | 设计和开发后台的`REST`的API时,记得要添加`CORS`支持,否则前端调用接口容易出现各种和`CORS`方面的问题,导致无法使用接口。 10 | 11 | 关于`CORS`的详见,见另外的教程:[CORS开发总结](https://book.crifan.com/books/cors_dev_ummary/website/ 12 | ) 13 | -------------------------------------------------------------------------------- /src/http_related/ch3_http_note_summary.md: -------------------------------------------------------------------------------- 1 | # HTTP相关心得 2 | 3 | ## iOS(swift)用Alamofire时,注意返回response时所处的线程 4 | 5 | iOS(swift)对于http库,[Alamofire的响应返回默认处于主的UI线程](https://github.com/Alamofire/Alamofire#response-handler-queue) 6 | 7 | -> 而很多耗时的操作,是不建议,不允许,在主线程中操作的 8 | 9 | -> 所以我后来自己在Alamofire基础上封装的库,是用`dispatchBackground_async`让`responseJSON`返回后运行在后台线程 10 | 11 | -> 避免大量的操作堵塞了UI的响应 12 | 13 | -> 又由于iOS中只能在主线程UI线程中操作UI元素 14 | 15 | -> 所以此时如果直接在Alamofire返回的地方去操作UI元素则会报错:`Terminating app due to uncaught exception NSInternalInconsistencyException reason Only run on the main thread`或`UI API called from background thread xx must be used from main thread only` 16 | 17 | 解决办法是: 18 | 19 | 对于每个Alamofire的返回的response时,自己根据需要,加上异步主线程,在其中处理UI操作的部分。 20 | 21 | 示例代码: 22 | 23 | ```swift 24 | func getUnreadCount(){ 25 | let url = ServerApi.getUnreadCountUrl() 26 | 27 | getUrlRespJson_async( 28 | httpMethod: .get, 29 | url: url, 30 | parameters: nil, 31 | respJsonHandle: { (response) in 32 | if response.isSuccess { 33 | if let count = response.successValue["count"].int { 34 | gLog.debug("count:\(count)") 35 | dispatchMain_async ({ 36 | if count <= 0{ 37 | self.tabBarItem.badgeValue = nil 38 | } else if count >= 100 { 39 | self.tabBarItem.badgeValue = "99+" 40 | } else { 41 | self.tabBarItem.badgeValue = "\(count)" 42 | } 43 | }) 44 | } 45 | } else if response.isFailure { 46 | dispatchMain_async ({ 47 | self.noticeInfo(response.failedMessage) 48 | }) 49 | } 50 | }) 51 | } 52 | ``` 53 | 54 | 在`respJsonHandle`中当`isSuccess`时,用`dispatchMain_async`确保处于主线程,然后才能去操作UI中的元素:`self.tabBarItem.badgeValue` 55 | 56 | 而对于上述函数详见: 57 | * http函数[CrifanLibHttp.swift](https://github.com/crifan/crifanLib/blob/master/swift/Http/CrifanLibHttp.swift)中的`getUrlRespJson_async` 58 | * 线程函数[CrifanThread.swift](https://github.com/crifan/crifanLib/blob/master/swift/Thread/CrifanThread.swift)中的`dispatchBackground_async` 59 | 60 | 相关帖子可参考: 61 | 62 | [[已解决]swift中Alamofire的request的responseJSON不执行不返回了](http://www.crifan.com/ios_swift_alamofire_request_responsejson_not_run_no_return) 63 | 64 | ## 断点续传就是利用Http的Range实现的 65 | 66 | 对于断点续传功能的实现,就是利用了HTTP的头Range去实现的: 67 | 68 | ![](/assets/img/http_range_download.png) 69 | 70 | 详见: 71 | 72 | [[已解决]swift 下载时支持断点续传](http://www.crifan.com/ios_swift_download_support_breakpoint_resume) -------------------------------------------------------------------------------- /src/http_related/ch4_http_file_upload.md: -------------------------------------------------------------------------------- 1 | # HTTP的文件上传 2 | 3 | 在HTTP相关开发期间,往往会涉及到上传文件,其中会涉及`multipart/form-data`。 4 | 5 | 而官方的HTTP和`multipart/form-data`相关的协议有: 6 | * [Returning Values from Forms: multipart/form-data](https://www.ietf.org/rfc/rfc2388.txt) 7 | * [Format of Internet Message Bodies](https://www.ietf.org/rfc/rfc2045.txt) 8 | * [Form submission](https://www.w3.org/TR/html401/interact/forms.html#h-17.13) 9 | 10 | 对于用HTTP的`multipart/form-data`实现文件上传: 11 | * 既有合适的如Postman等工具方便去调试 12 | * 也有iOS中Alamofire等库很好的支持 13 | * (如果清楚协议详情)也可以自己手动写代码拼接出`multipart/form-data`所需要的字段和内容去实现文件上传 14 | 15 | 下面就来详细介绍这方面的内容。 16 | 17 | ### iOS中Alamofire支持文件上传的`MultipartFormData` 18 | 可以基本实现文件上传的iOS的Alamofire的代码: 19 | ```swift 20 | func uploadImageData(imageData:NSData){ 21 | dispatchBackground_async({ 22 | gLog.verbose("imageData.length=\(imageData.length)") 23 | 24 | self.pleaseWait() 25 | 26 | var curHeader = Dictionary() 27 | curHeader["authenticate"] = "token " + gCurUserItem.accessToken 28 | 29 | gLog.verbose("curHeader=\(curHeader)") 30 | 31 | let curDate = NSDate() 32 | 33 | let name = "file" 34 | let filename = curDate.toString("yyyyMMdd_hhmmss") + ".jpg" 35 | gLog.verbose("name=\(name), filename=\(filename)") 36 | //uploadImageData > name=file, filename=20160625_085958.jpg 37 | 38 | Alamofire.upload( 39 | .POST, 40 | ServerApi.uploadFileUrl(gCurUserItem.id), 41 | headers: curHeader, 42 | multipartFormData: {multipartFormData in 43 | multipartFormData.appendBodyPart( 44 | data: imageData, 45 | name: name, 46 | fileName: filename, 47 | mimeType: "image/jpeg" 48 | ) 49 | }, 50 | 51 | encodingCompletion: { encodingResult in 52 | gLog.verbose("encodingResult=\(encodingResult)") 53 | /* 54 | encodingResult=Success($ curl -i \ 55 | -X POST \ 56 | -H "User-Agent: Xxx App/com.xxx.YyyApp (2016.6.24; OS ban ben 9.3(ban hao 13E230))" \ 57 | -H "authenticate: token zzzzzz" \ 58 | -H "Content-Type: multipart/form-data; boundary=alamofire.boundary.5fd5efc56016a4df" \ 59 | -H "Accept-Encoding: gzip;q=1.0, compress;q=0.5" \ 60 | -H "Accept-Language: en-US;q=1.0, zh-Hans-US;q=0.9" \ 61 | "http://192.168.1.102:8080/app/user/10000010/upload", false, nil) 62 | 63 | encodingResult=Success($ curl -i \ 64 | -X POST \ 65 | -H "User-Agent: Xxx App/com.xxx.YyyApp (2016.6.24; OS ban ben 9.3(ban hao 13E230))" \ 66 | -H "authenticate: token zzzzzz" \ 67 | -H "Content-Type: multipart/form-data; boundary=alamofire.boundary.01fc8db6b551cd51" \ 68 | -H "Accept-Encoding: gzip;q=1.0, compress;q=0.5" \ 69 | -H "Accept-Language: en-US;q=1.0, zh-Hans-US;q=0.9" \ 70 | "http://xxx.yyy.cn/app/user/10000010/upload", false, nil) 71 | */ 72 | 73 | switch encodingResult { 74 | //case .Success(let uploadRequest, streamingFromDisk, streamFileURL): 75 | case .Success(let uploadRequest, _, _): 76 | // gLog.verbose("uploadRequest=\(uploadRequest), streamingFromDisk=\(streamingFromDisk), streamFileURL=\(streamFileURL)") 77 | gLog.verbose("uploadRequest=\(uploadRequest)") 78 | //upload=POST http://192.168.1.102:8080/app/user/10000010/upload 79 | //uploadRequest=POST http://xxx.yyy.cn/app/user/10000010/upload 80 | 81 | uploadRequest.responseJSON(completionHandler: 82 | { response in 83 | gLog.verbose("response=\(response)") 84 | /* 85 | response=SUCCESS: { 86 | code = 200; 87 | data = { 88 | created = 1466850689624; 89 | id = 1000001020160625103129624; 90 | location = ""; 91 | name = "image.jpg"; 92 | owner = ""; 93 | uploader = 10000010; 94 | }; 95 | message = ok; 96 | } 97 | 98 | response=SUCCESS: { 99 | errors = ( 100 | "The request body may not be null", 101 | "The request body may not be null" 102 | ); 103 | } 104 | 105 | response=SUCCESS: { 106 | code = 200; 107 | data = { 108 | created = 1466859610413; 109 | id = 1000001020160625130010413; 110 | location = ""; 111 | name = "20160625_085958.jpg"; 112 | owner = ""; 113 | uploader = 10000010; 114 | }; 115 | message = ok; 116 | } 117 | */ 118 | 119 | switch response.result { 120 | case .Success(let value): 121 | let valueJson = JSON(value) 122 | gLog.verbose("\(valueJson)") 123 | /* 124 | { 125 | "message" : "ok", 126 | "code" : 200, 127 | "data" : { 128 | "name" : "image.jpg", 129 | "id" : "1000001020160625103129624", 130 | "uploader" : 10000010, 131 | "location" : null, 132 | "created" : 1466850689624, 133 | "owner" : null 134 | } 135 | } 136 | */ 137 | 138 | let statusCode = valueJson["code"].int ?? 0 139 | if statusCode == 200 { 140 | let dataObj = valueJson["data"].object 141 | let dataJson:JSON = JSON(dataObj) 142 | self.uploadAttachmentsHandler(Alamofire.Result.Success(dataJson)) 143 | gLog.verbose("dataJson=\(dataJson)") 144 | 145 | } else { 146 | self.noticeError("上传附件出错", autoClear: true, autoClearTime: 1) 147 | 148 | let message = valueJson["message"].string ?? "" 149 | let messageStrArr = message.splitToStrArr("|") 150 | 151 | var messageStr:String = message 152 | var subCode:Int = 0 153 | 154 | if messageStrArr.count > 1 { 155 | messageStr = messageStrArr[0] 156 | subCode = Int(messageStrArr[1]) ?? 0 157 | } 158 | 159 | let error:NSError = NSError(domain: HttpErrorDomain, code: statusCode, userInfo: [ 160 | "message" : messageStr, 161 | "code" : statusCode, 162 | "subCode" : subCode, 163 | ]) 164 | 165 | self.uploadAttachmentsHandler(Alamofire.Result.Failure(error)) 166 | } 167 | case .Failure(let error): 168 | gLog.verbose("error=\(error)") 169 | self.uploadAttachmentsHandler(Alamofire.Result.Failure(error)) 170 | } 171 | }) 172 | 173 | case .Failure(let encodingError): 174 | gLog.error("上传附件失败\(encodingError)") 175 | } 176 | } 177 | ) 178 | 179 | }) 180 | } 181 | ``` 182 | 183 | 详见: 184 | 185 | [[已解决]Alamofire中multipartFormData中的name和filename到底应该是什么值](http://www.crifan.com/ios_swift_alamofire_upload_multipartformdata_name_filename_meaning) 186 | 187 | ### Postman中可以方便的调试文件上传 188 | 当然,如果后台设计的不是很规范,则可能导致,即使传入了标准的参数设置: 189 | * POST xxx/xxx/upload 190 | * Headers 191 | * `Authorization: Bearer 6c9f198878cb42e6aad83fecbb598d10_8a9bfdab5a21ca27015a21d72fb20000` 192 | * `Content-Type: multipart/form-data;boundary=any_random_value` 193 | * `Accept: application/json` 194 | 195 | 却仍可能会返回错误`HTTP 415 Unsupported Media Type` 196 | 197 | 详见: 198 | 199 | [【已解决】Mac中Postman去POST实现文件上传时出错:HTTP 415 Unsupported Media Type – 在路上](https://www.crifan.com/mac_postman_post_upload_file_error_http_415_unsupported_media_type/) 200 | 201 | 但是本身[Postman](https://github.com/crifan/api_tool_postman)对于文件上传的支持,还是很方便很好用的。 202 | 203 | ### C\#中如何手动裸写`multipart/form-data`的文件上传 204 | 之前也曾折腾过,自己用C#代码拼凑出`multipart/form-data`所需要的内容的格式。 205 | 206 | 如此折腾后,算是对于`multipart/form-data`有了更深入的认识。 207 | 208 | 详见: 209 | 210 | [【教程】模拟登陆之如何分析并用代码模拟上传文件 – 在路上](https://www.crifan.com/emulate_login_example_for_analysis_and_write_code_for_emulate_upload_file/) 211 | 212 | 213 | -------------------------------------------------------------------------------- /src/http_related/ch5_mixed_content.md: -------------------------------------------------------------------------------- 1 | # 混合内容 2 | 3 | 当很多网站提高安全性,而把`http`的域名,都改为`https`了。 4 | 5 | 但是如果在此期间网站内部没有完全处理好,残留部分`http`的链接,则就会出现: 6 | 7 | `Mixed Content`=`混合内容`=`http网页中加载了http的内容/资源` 8 | 9 | 不同浏览器对Mixed Content 有不一样的处理规则。 10 | 11 | 此处暂时不需要深究。知道有这个事情即可。 -------------------------------------------------------------------------------- /src/http_related/tool_lib/README.md: -------------------------------------------------------------------------------- 1 | # HTTP的工具和库 2 | -------------------------------------------------------------------------------- /src/http_related/tool_lib/lib.md: -------------------------------------------------------------------------------- 1 | # HTTP库 2 | 3 | 此处整理不同编程语言的HTTP方面的库: 4 | 5 | ### `iOS`的`swift`/`Obj-C` 6 | 7 | * 第三方 8 | * [Alamofire](https://github.com/Alamofire/Alamofire) 9 | * swift 10 | * [SwiftHTTP](https://github.com/daltoniam/SwiftHTTP) 11 | 12 | ### Python 13 | 14 | * 内置 15 | * Python 3 16 | * https://docs.python.org/3/library/urllib.html 17 | * Python 2 18 | * urllib 19 | * https://docs.python.org/2/library/urllib.html 20 | * urllib2 21 | * https://docs.python.org/2/library/urllib2.html 22 | * 第三方 23 | * [Requests](https://github.com/requests/requests) 24 | * 详见独立教程 25 | * [Python心得:http网络库](http://book.crifan.com/books/python_summary_http_lib/website) 26 | 27 | ### JavaScript 28 | 29 | * 好用的 30 | * axios 31 | * https://github.com/axios/axios 32 | * 其他的 33 | * Request 34 | * https://github.com/request/request 35 | * Web API的Fetch 36 | * https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API 37 | * SuperAgent 38 | * https://github.com/visionmedia/superagent 39 | * fetch 40 | * https://github.com/github/fetch 41 | * 举例 42 | ```js 43 | import ‘whatwg-fetch’; 44 | fetch( 45 | ‘http://xxxxx/getProgressData’, 46 | { 47 | method : ‘POST’, 48 | headers : { 49 | ‘Content-Type’: ‘application/x-www-form-urlencoded; charset=UTF-8’, 50 | ‘Accept’: ‘application/json’ 51 | }, 52 | body: ‘currTime=2017-08-25&orgCode=SK316005’ 53 | } 54 | ) 55 | .then((resp) => { 56 | console.log(resp); 57 | let respJson = resp.json(); //typeof(respJson)= object 58 | console.log(‘respJson=’, respJson, ‘typeof(respJson)=’, typeof(respJson)); 59 | return respJson; 60 | }) 61 | .then((respJsonDict) => { 62 | console.log(‘parsed respJsonDict=’, respJsonDict); 63 | }); 64 | ``` 65 | * 效果 66 | * 返回的是object对象,是Response类型,其中json()之后得到的是Promise对象,也就是可以直接拿来使用的json对象了,然后就可以进行后序数据处理了 67 | * ![http_lib_js_fetch_resp](../../assets/img/http_lib_js_fetch_resp.png) 68 | 69 | ### C# 70 | 71 | - [HttpWebRequest](https://msdn.microsoft.com/en-us/library/system.net.httpwebrequest(v=vs.110).aspx) 72 | * crifan的lib的C#的http的部分 73 | * [第 9 章 crifanLib.cs之Http](https://www.crifan.com/files/doc/docbook/crifanlib_csharp/release/html/crifanlib_csharp.html#http) 74 | -------------------------------------------------------------------------------- /src/http_related/tool_lib/tool.md: -------------------------------------------------------------------------------- 1 | # HTTP工具 2 | 3 | 此处整理HTTP相关的库和工具: 4 | 5 | ## Postman 6 | 7 | 可用于服务器端和其他移动端等,调试接口数据返回是否正常 8 | 9 | 举例:比如用Postman去调试奶牛云的后台的登录接口: 10 | 11 | ![](../assets/img/38CFDEB6-8637-4C7C-AC2E-14C7F3AD9B5A.png) 12 | 13 | 更多内容详见另外的教程:[API开发利器:Postman](http://book.crifan.com/books/api_tool_postman/website/) 14 | 15 | ## Chrome的开发者工具Developer Tools 16 | 17 | 调试页面内容是否正常,包括布局,参数等等 18 | 19 | 详见:[【总结】浏览器中的开发人员工具(IE9的F12和Chrome的Ctrl+Shift+I)-网页分析的利器](https://www.crifan.com/browser_developer_tool_chrome_vs_ie9/) 20 | 21 | ## curl 22 | 23 | 模拟去请求服务器数据的命令行工具 24 | 25 | ## HTTPie 26 | 27 | 后来从[jobbole/awesome-python-cn: Python资源大全中文版](https://github.com/jobbole/awesome-python-cn)中知道了还有个`HTTPie` 28 | 29 | * Github: [jakubroztocil/httpie: Modern command line HTTP client](https://github.com/jakubroztocil/httpie) 30 | * 官网:[HTTPie – command line HTTP client](https://httpie.org) 31 | * 简介: 32 | * > HTTPie is a command line HTTP client with an intuitive UI, JSON support, syntax highlighting, wget-like downloads, plugins, and more 33 | 34 | 看了下,比curl更好用,更方便。值得推荐。 35 | 36 | ## Httpbin 37 | 38 | Httpbin 是一个网站: 39 | 40 | http://httpbin.org/ 41 | 42 | 用于测试http各方面的内容。 43 | 44 | 首页: 45 | 46 | ![httpbin_org_home](../../assets/img/httpbin_org_home.png) 47 | 48 | 比如: 49 | 50 | 51 | ### get 52 | 53 | 测试get方法: 54 | 55 | http://httpbin.org/get 56 | 57 | 返回各种信息,包括headers 58 | 59 | ```json 60 | { 61 | "args": {}, 62 | "headers": { 63 | "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", 64 | "Accept-Encoding": "gzip, deflate", 65 | "Accept-Language": "zh-cn", 66 | "Cookie": "_gauges_unique=1", 67 | "Host": "httpbin.org", 68 | "Upgrade-Insecure-Requests": "1", 69 | "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_2) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.0.2 Safari/605.1.15" 70 | }, 71 | "origin": "222.92.130.218, 222.92.130.218", 72 | "url": "https://httpbin.org/get" 73 | } 74 | ``` 75 | 76 | ![httpbin_get_resp](../../assets/img/httpbin_get_resp.png) 77 | 78 | 目的和作用:可以通过你的代码或工具中,去调用 http://httpbin.org/get ,从返回的值中,确认你的接口调用GET时的各种参数,是否符合你的预期 79 | 80 | ### ip 81 | 82 | 去测试当前IP: 83 | 84 | http://httpbin.org/ip 85 | 86 | 返回: 87 | 88 | ```json 89 | { 90 | "origin": "222.92.130.218, 222.92.130.218" 91 | } 92 | ``` 93 | 94 | ![httpbin_ip_resp](../../assets/img/httpbin_ip_resp.png) 95 | 96 | 用途举例: 97 | 98 | 【已解决】PySpider中使用多贝云IP代理池实现每次请求IP都不同 99 | 100 | 中就利用了: 101 | 102 | http://httpbin.org/ip 103 | 104 | 去获取当前(代理)的IP,来确认每次通过代理访问时,代理IP地址是否正确,代理是否真的生效了。 105 | 106 | ### json 107 | 108 | 你想要测试,返回json数据,写代码去解析json 109 | 110 | 可以用: 111 | 112 | http://httpbin.org/json 113 | 114 | 返回json数据供你解析和测试代码 115 | 116 | 同时,该网页上还有测试界面供你测试数据效果: 117 | 118 | ![httpbin_json_format](../../assets/img/httpbin_json_format.png) 119 | 120 | 点击Execute后效果: 121 | 122 | ![httpbin_json_formatted](../../assets/img/httpbin_json_formatted.png) 123 | --------------------------------------------------------------------------------