-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
311 additions
and
333 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php declare(strict_types=1); | ||
|
||
require dirname(__DIR__) . '/test/bootstrap.php'; | ||
|
||
/** | ||
* # example 1 获取一个页面并发送 POST 数据 | ||
* | ||
* @link https://secure.php.net/manual/zh/context.http.php#refsect1-context.http-examples | ||
*/ | ||
|
||
$postdata = http_build_query( | ||
[ | ||
'var1' => 'some content', | ||
'var2' => 'doh' | ||
] | ||
); | ||
|
||
$opts = [ | ||
'http' => | ||
[ | ||
'method' => 'POST', | ||
'header' => 'Content-type: application/x-www-form-urlencoded', | ||
'content' => $postdata | ||
] | ||
]; | ||
|
||
$context = stream_context_create($opts); | ||
$result = file_get_contents('http://example.com/submit.php', false, $context); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php declare(strict_types=1); | ||
|
||
require dirname(__DIR__) . '/test/bootstrap.php'; | ||
|
||
/** | ||
* @see https://secure.php.net/manual/zh/context.http.php#114867 | ||
*/ | ||
|
||
// php 5.4 : array syntax and header option with array value | ||
$data = file_get_contents('http://www.example.com/', false, stream_context_create([ | ||
'http' => [ | ||
'protocol_version' => 1.1, | ||
'header' => [ | ||
'Connection: close', | ||
], | ||
], | ||
])); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php declare(strict_types=1); | ||
|
||
require dirname(__DIR__) . '/test/bootstrap.php'; | ||
|
||
/** | ||
* @link https://secure.php.net/manual/zh/context.http.php#110449 | ||
*/ | ||
|
||
$stream = stream_context_create([ | ||
'http' => [ | ||
'method' => 'GET', | ||
'timeout' => 20, | ||
'header' => 'User-agent: Myagent', | ||
'proxy' => 'tcp://my-proxy.localnet:3128', | ||
'request_fulluri' => true /* without this option we get an HTTP error! */ | ||
] | ||
]); | ||
|
||
if ($fp = fopen('http://example.com', 'rb', false, $stream)) { | ||
print 'well done'; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php declare(strict_types=1); | ||
|
||
require dirname(__DIR__) . '/test/bootstrap.php'; | ||
|
||
/** | ||
* # example 2 忽略重定向并获取 header 和内容 | ||
* | ||
* @link https://secure.php.net/manual/zh/context.http.php#refsect1-context.http-examples | ||
*/ | ||
|
||
$url = 'http://www.example.org/header.php'; | ||
|
||
$opts = [ | ||
'http' => | ||
[ | ||
'method' => 'GET', | ||
'max_redirects' => '0', | ||
'ignore_errors' => '1' | ||
] | ||
]; | ||
|
||
$context = stream_context_create($opts); | ||
$stream = fopen($url, 'rb', false, $context); | ||
|
||
// header information as well as meta data | ||
// about the stream | ||
vdump(stream_get_meta_data($stream)); | ||
|
||
// actual data at $url | ||
vdump(stream_get_contents($stream)); | ||
fclose($stream); | ||
|
This file was deleted.
Oops, something went wrong.
File renamed without changes.
Oops, something went wrong.