{"id":356,"date":"2017-04-12T18:57:16","date_gmt":"2017-04-12T10:57:16","guid":{"rendered":"https:\/\/blog.freesilo.com\/?p=356"},"modified":"2017-04-12T19:06:29","modified_gmt":"2017-04-12T11:06:29","slug":"fsockopen-%e5%ae%9e%e7%8e%b0%e6%a8%a1%e6%8b%9f%e7%bd%91%e7%ab%99%e8%af%b7%e6%b1%82","status":"publish","type":"post","link":"https:\/\/freesilo.com\/?p=356","title":{"rendered":"fsockopen \u5b9e\u73b0\u6a21\u62df\u7f51\u7ad9\u8bf7\u6c42"},"content":{"rendered":"<p>\u53ef\u4ee5\u4f7f\u7528fsockopen\u5b9e\u73b0\u7b80\u5355\u7684\u5f02\u6b65\u8bf7\u6c42\uff0c\u6a21\u62dfhttp\u62a5\u6587\u8bf7\u6c42\uff0c\u8fd9\u91cc\u662f\u5173\u4e8e post\u8bf7\u6c42\u7684\u4f8b\u5b50\uff1a<br \/>\nclient.php<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n&lt;?php \r\nheader('Content-type: text\/html;charset=utf8'); \r\n$url = 'http:\/\/h5.cleey.com\/home\/index\/index'; \r\n$post = array( 'mid' =&gt; 23, 'more'=&gt; 'hello' );\r\nsock_post($url,$post);\r\n\r\nfunction sock_post($url,$post){\r\n\t$info = parse_url($url);  \/\/ \u89e3\u6790url\r\n\t$text = http_build_query($post);\r\n\t\r\n\t\/\/ \u4e0e\u670d\u52a1\u5668\u5efa\u7acb\u8fde\u63a5\r\n\t\/\/ \u53c2\u6570\u610f\u4e49\uff1ah5.cleey.com\uff08\u4e5f\u53ef\u4ee5\u76f4\u63a5\u5199IP\uff09,\u7aef\u53e3\uff0c\u9519\u8bef\u7f16\u53f7\uff0c\u9519\u8bef\u4fe1\u606f\uff0c\u8d85\u65f6\u65f6\u95f4.\r\n\t\/\/ \u5229\u7528\u8d85\u65f6\u65f6\u95f4\u53ef\u4ee5\u5f88\u77ed\u7684\u9000\u51fa\u3002\u800c\u76ee\u6807\u5730\u5740\uff0c\u53ef\u4ee5ignore user abort\uff0c\u7ee7\u7eed\u6267\u884c\u3002\r\n\t$fp = fsockopen($info&#x5B;'host'], 80, $errno, $errstr, 1000) ;\r\n\tif (!$fp) { echo &quot;$errstr ($errno)\r\n\\n&quot;;return; }\r\n\r\n\t\/\/ \u6a21\u62dfhttp \u62a5\u6587\u4e86\u3002\r\n\t$out = &quot;POST {$info&#x5B;'path']}?{$info&#x5B;'query']} HTTP\/1.1\\r\\n&quot;;\r\n\t$out .= &quot;Host: {$info&#x5B;'host']}\\r\\n&quot;;\r\n\t$out .= &quot;Content-type:application\/x-www-form-urlencoded\\r\\n&quot;;\r\n\t$out .= &quot;Content-length: &quot;.strlen($text).&quot;\\r\\n&quot;;\r\n\t$out .= &quot;Connection: close\\r\\n\\r\\n&quot;;\r\n\t$out .= $text;\r\n\tfputs($fp, $out); \/\/ \u505a\u8bf7\u6c42\u3002\r\n\r\n\t\/*\u6267\u884c\u7ed3\u679c \u53ef\u4ee5\u76f4\u63a5\u5ffd\u7565\uff0c\u6211\u4eec\u53ea\u9700\u901a\u77e5\u76ee\u6807\u5730\u5740\u5c31\u884c\u4e86\uff0c\u4e0d\u9700\u8981\u77e5\u9053\u6267\u884c\u7ed3\u679c*\/\r\n\techo '\r\n\r\n&lt;pre&gt;';\r\n\twhile (!feof($fp)) { echo fgets($fp, 1024); }\r\n\t\/*\u6267\u884c\u7ed3\u679c \u7ed3\u675f*\/\r\n\r\n\tfclose($fp);\r\n}\r\n\r\n\r\n?&gt;\r\n<\/pre>\n<p>sever.php<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\necho 'Welcome to use PhpPoem!';\r\necho '&lt;pre&gt;';\r\necho '$_REQUEST \u53d8\u91cf\u4e3a:&lt;br&gt;';\r\nvar_export($_REQUEST);\r\nexit;\r\n<\/pre>\n<p>\u6267\u884c client.php \u7684\u7ed3\u679c\u5982\u4e0b\uff1a<\/p>\n<pre class=\"prettyprint prettyprinted\"><span class=\"pln\">HTTP<\/span><span class=\"pun\">\/<\/span><span class=\"lit\">1.1<\/span> <span class=\"lit\">200<\/span><span class=\"pln\"> OK\r\n<\/span><span class=\"typ\">Server<\/span><span class=\"pun\">:<\/span><span class=\"pln\"> nginx<\/span><span class=\"pun\">\/<\/span><span class=\"lit\">1.0<\/span><span class=\"pun\">.<\/span><span class=\"lit\">15<\/span>\r\n<span class=\"typ\">Date<\/span><span class=\"pun\">:<\/span> <span class=\"typ\">Mon<\/span><span class=\"pun\">,<\/span> <span class=\"lit\">14<\/span> <span class=\"typ\">Mar<\/span> <span class=\"lit\">2016<\/span> <span class=\"lit\">03<\/span><span class=\"pun\">:<\/span><span class=\"lit\">30<\/span><span class=\"pun\">:<\/span><span class=\"lit\">31<\/span><span class=\"pln\"> GMT\r\n<\/span><span class=\"typ\">Content<\/span><span class=\"pun\">-<\/span><span class=\"typ\">Type<\/span><span class=\"pun\">:<\/span><span class=\"pln\"> text<\/span><span class=\"pun\">\/<\/span><span class=\"pln\">html<\/span><span class=\"pun\">;<\/span><span class=\"pln\">charset<\/span><span class=\"pun\">=<\/span><span class=\"pln\">utf<\/span><span class=\"pun\">-<\/span><span class=\"lit\">8<\/span>\r\n<span class=\"typ\">Transfer<\/span><span class=\"pun\">-<\/span><span class=\"typ\">Encoding<\/span><span class=\"pun\">:<\/span><span class=\"pln\"> chunked\r\n<\/span><span class=\"typ\">Connection<\/span><span class=\"pun\">:<\/span><span class=\"pln\"> close\r\nX<\/span><span class=\"pun\">-<\/span><span class=\"typ\">Powered<\/span><span class=\"pun\">-<\/span><span class=\"typ\">By<\/span><span class=\"pun\">:<\/span> <span class=\"typ\">PhpPoem_v2<\/span><span class=\"pun\">.<\/span><span class=\"lit\">0<\/span>\r\n\r\n<span class=\"lit\">63<\/span>\r\n<span class=\"typ\">Welcome<\/span><span class=\"pln\"> to <\/span><span class=\"kwd\">use<\/span> <span class=\"typ\">PhpPoem<\/span><span class=\"pun\">!<\/span><span class=\"pln\">\r\n$_REQUEST <\/span><span class=\"pun\">\u53d8\u91cf\u4e3a:<\/span><span class=\"pln\">\r\narray <\/span><span class=\"pun\">(<\/span>\r\n  <span class=\"str\">'mid'<\/span> <span class=\"pun\">=&gt;<\/span> <span class=\"str\">'23'<\/span><span class=\"pun\">,<\/span>\r\n  <span class=\"str\">'more'<\/span> <span class=\"pun\">=&gt;<\/span> <span class=\"str\">'hello'<\/span><span class=\"pun\">,<\/span>\r\n<span class=\"pun\">)<\/span>\r\n<span class=\"lit\">0<\/span><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u53ef\u4ee5\u4f7f\u7528fsockopen\u5b9e\u73b0\u7b80\u5355\u7684\u5f02\u6b65\u8bf7\u6c42\uff0c\u6a21\u62dfhttp\u62a5\u6587\u8bf7\u6c42\uff0c\u8fd9\u91cc\u662f\u5173\u4e8e &#8230;<br \/><a class=\"read-more-button\" href=\"https:\/\/freesilo.com\/?p=356\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-356","post","type-post","status-publish","format-standard","hentry","category-php"],"_links":{"self":[{"href":"https:\/\/freesilo.com\/index.php?rest_route=\/wp\/v2\/posts\/356","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/freesilo.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/freesilo.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/freesilo.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/freesilo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=356"}],"version-history":[{"count":5,"href":"https:\/\/freesilo.com\/index.php?rest_route=\/wp\/v2\/posts\/356\/revisions"}],"predecessor-version":[{"id":531,"href":"https:\/\/freesilo.com\/index.php?rest_route=\/wp\/v2\/posts\/356\/revisions\/531"}],"wp:attachment":[{"href":"https:\/\/freesilo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=356"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/freesilo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=356"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/freesilo.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=356"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}