Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 64803ba

Browse files
Added support for POST requests.
1 parent 1194c7d commit 64803ba

File tree

4 files changed

+61
-13
lines changed

4 files changed

+61
-13
lines changed

‎README.md‎

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,46 +10,82 @@ Visit [here](https://php-simple-web-scraper.herokuapp.com/).
1010

1111
## Usage
1212

13+
### Basic Usage
1314
Perform an HTTP request with the `url` query parameter and encoded URL as a value.
1415

1516
```
1617
http(s)://{app-address}/?url={encoded target url}
1718
```
1819

19-
### Example
20+
#### Example
2021
```
2122
http(s)://{app-address}/?url=https%3A%2F%2Fgithub.com
2223
```
2324

24-
## Supported Ouput Types
25+
### Parameters
26+
#### output
27+
Determines the output type, which includes `html`, `json`, `screenshot`.
2528

26-
###HTML (default)
29+
##### html (default)
2730

2831
HTML source code of the target web site. JavaScript generated contents are also retrieved and dumped.
2932

30-
### JSON
31-
HTTP response data as JSON. Useful for cross site communications with JSONP.
33+
##### json
3234

33-
#### Parameter
3435
`output=json`
3536

36-
#### Example
37+
HTTP response data as JSON. Useful for cross site communications with JSONP.
38+
39+
###### Example
3740
```
3841
http(s)://{app-address}/?url=https%3A%2F%2Fgithub.com&output=json
3942
```
4043

41-
### Screenshot (Web Snapshot)
42-
A jpeg image of the site snapshot.
44+
##### screenshot
4345

44-
45-
#### Parameter
4646
`output=screenshot`
4747

48-
#### Example
48+
A jpeg image of the site snapshot.
49+
50+
###### Example
4951
```
5052
http(s)://{app-address}/?url=https%3A%2F%2Fgithub.com&output=screenshot
5153
```
5254

55+
#### user-agent
56+
Sets a custom user agent. By default, a random user-agent will be assigned. You can change it by specifying the value with this parameter.
57+
58+
##### Example
59+
To set a user agent, `Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:57.0) Gecko/20100102 Firefox/57.0`,
60+
```
61+
http(s)://{app-address}/?url=https%3A%2F%2Fwww.whatismybrowser.com%2Fdetect%2Fwhat-http-headers-is-my-browser-sending&user-agent=Mozilla/5.0%20(Windows%20NT%206.1;%20Win64;%20x64;%20rv:57.0)%20Gecko/20100102%20Firefox/57.0
62+
```
63+
64+
#### headers
65+
Sets a custom HTTP headers. Accepts the value as an array.
66+
67+
##### Example
68+
To set `DNT` value,
69+
```
70+
http(s)://{app-address}/?url=https%3A%2F%2Fwww.whatismybrowser.com%2Fdetect%2Fwhat-http-headers-is-my-browser-sending&headers[DNT]=1
71+
```
72+
73+
#### method
74+
HTTP request method. Default: `GET`. Accepts the followings.
75+
- OPTIONS
76+
- GET
77+
- HEAD
78+
- POST
79+
- PUT
80+
- DELETE
81+
- PATCH
82+
83+
When using `POST`, give sending post data with the `data` request key. The program checks `$_REQUEST[ 'data' ]` to send POST data.
84+
##### Example
85+
```
86+
http(s)://{app-address}/?url=http%3A%2F%2Fhttpbin.org%2Fpost&method=POST&data[foo]=bar
87+
```
88+
5389
## Run as Heroku Application
5490
This is a Heroku application and meant to be deployed to a [Heroku](https://dashboard.heroku.com/) application instance.
5591

‎web/include/class/Browser.php‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ public function get( $sURL, $sMethod='GET' ) {
1616
// @see http://jonnnnyw.github.io/php-phantomjs/4.0/3-usage/#custom-headers
1717
$request->addHeaders( $this->_aHeaders );
1818

19+
// @see http://jonnnnyw.github.io/php-phantomjs/3.0/3-usage/#post-request
20+
if ( 'POST' === $sMethod ) {
21+
$_aData = isset( $_REQUEST[ 'data' ] ) ? $_REQUEST[ 'data' ] : array();
22+
$request->setRequestData( $_aData ); // Set post data
23+
}
24+
1925
$response = $this->oClient->getMessageFactory()->createResponse();
2026

2127
$this->oClient->send( $request, $response );

‎web/include/class/ScreenCapture.php‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ public function get( $sURL, $sOutputFilePath, $sMethod='GET' ) {
2828
// @see http://jonnnnyw.github.io/php-phantomjs/4.0/3-usage/#custom-headers
2929
$request->addHeaders( $this->_aHeaders );
3030

31+
// @see http://jonnnnyw.github.io/php-phantomjs/3.0/3-usage/#post-request
32+
if ( 'POST' === $sMethod ) {
33+
$_aData = isset( $_REQUEST[ 'data' ] ) ? $_REQUEST[ 'data' ] : array();
34+
$request->setRequestData( $_aData ); // Set post data
35+
}
36+
3137
$response = $this->oClient->getMessageFactory()->createResponse();
3238

3339
// Send the request

‎web/index.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ static public function setUp() {
6060
: array();
6161

6262
$_sMethod = isset( $_REQUEST[ 'method' ] )
63-
? $_REQUEST[ 'method' ]
63+
? strtoupper( $_REQUEST[ 'method' ] )
6464
: 'GET';
6565

6666
/// Requests by type

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /