{"id":226514,"date":"2021-09-24T08:59:11","date_gmt":"2021-09-24T00:59:11","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=226514"},"modified":"2021-09-14T09:00:07","modified_gmt":"2021-09-14T01:00:07","slug":"go-bind-host","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/go-bind-host.html","title":{"rendered":"Go \u4ee3\u7801\u4e2d\u5982\u4f55\u7ed1\u5b9a Host"},"content":{"rendered":"
\u5bfc\u8bfb<\/td>\n | \u5728\u516c\u53f8\u5185\u90e8\uff0c\u4e3a\u4e86\u5b89\u5168\uff0c\u53ef\u80fd\u4f1a\u6709\u57df\u540d\u662f\u9700\u8981\u7ed1\u5b9a host \u624d\u80fd\u8bbf\u95ee\u7684\uff0c\u5982\u679c\u662f\u901a\u8fc7\u6d4f\u89c8\u5668\u8bbf\u95ee\uff0c\u6211\u4eec\u4f1a\u4fee\u6539\u672c\u673a\u7684 hosts \u6587\u4ef6;\u7136\u800c\uff0c\u5982\u679c\u662f\u8981\u901a\u8fc7\u7a0b\u5e8f\u8bbf\u95ee\u8fd9\u6837\u7684\u57df\u540d\uff0c\u6211\u4eec\u662f\u5426\u4f9d\u7136\u5fc5\u987b\u7ed1\u5b9a host \u5462? \n<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n <\/p>\n \u5728\u516c\u53f8\u5185\u90e8\uff0c\u4e3a\u4e86\u5b89\u5168\uff0c\u53ef\u80fd\u4f1a\u6709\u57df\u540d\u662f\u9700\u8981\u7ed1\u5b9a host \u624d\u80fd\u8bbf\u95ee\u7684\uff0c\u5982\u679c\u662f\u901a\u8fc7\u6d4f\u89c8\u5668\u8bbf\u95ee\uff0c\u6211\u4eec\u4f1a\u4fee\u6539\u672c\u673a\u7684 hosts \u6587\u4ef6;\u7136\u800c\uff0c\u5982\u679c\u662f\u8981\u901a\u8fc7\u7a0b\u5e8f\u8bbf\u95ee\u8fd9\u6837\u7684\u57df\u540d\uff0c\u6211\u4eec\u662f\u5426\u4f9d\u7136\u5fc5\u987b\u7ed1\u5b9a host \u5462?\u7b54\u6848\u5f53\u7136\u662f\u5426\u5b9a\u7684\uff0c\u800c\u4e14\uff0c\u4f9d\u8d56\u672c\u5730\u7ed1\u5b9a\u7684 host\uff0c\u7a0b\u5e8f\u5230\u5176\u4ed6\u673a\u5668\u90e8\u7f72\uff0c\u4e5f\u5fc5\u987b\u5728\u90a3\u53f0\u673a\u5668\u7ed1\u5b9a host\uff0c\u5982\u679c\u673a\u5668\u5f88\u591a\u5462?<\/p>\n \u521a\u597d\u524d\u4e24\u5929\uff0c\u7fa4\u91cc\u4e5f\u6709\u4eba\u95ee\u7c7b\u4f3c\u7684\u95ee\u9898<\/p>\n \u672c\u6587\u793a\u4f8b\uff1a<\/p>\n \u9700\u6c42\uff1a\u9700\u8981\u8bf7\u6c42\u670d\u52a1\u5668\u4e0a\u7684 testhost.txt \u8d44\u6e90\u3002<\/p>\n 1\u3001Linux Shell \u7684\u89e3\u51b3\u65b9\u6848<\/strong><\/div>\n Linux \u4e0b\u7684 curl \u7a0b\u5e8f\u53ef\u4ee5\u7ed1\u5b9a host\uff0c\u56e0\u6b64\uff0c\u5728 shell \u4e2d\u53ef\u4ee5\u5f88\u7b80\u5355\u7684\u5b9e\u73b0\uff0c\u5982\uff1acurl -H \"Host:studygolang.com\" http:\/\/192.168.1.102\/testhost.txt\u3002<\/p>\n 2\u3001PHP \u7684\u89e3\u51b3\u65b9\u6848<\/strong><\/div>\n 1)\u901a\u8fc7 curl \u6269\u5c55\u5b9e\u73b0<\/p>\n \r\n$ch = curl_init(); \r\ncurl_setopt($ch, CURLOPT_HTTPHEADER, array('Host:studygolang.com')); \r\ncurl_setopt($ch, CURLOPT_URL, 'http:\/\/192.168.1.102\/testhost.txt'); \r\ncurl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); \r\n$ret = curl_exec($ch); \r\nvar_dump($ret); <\/pre>\n |