-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathMain.class.php
More file actions
173 lines (151 loc) · 5.68 KB
/
Main.class.php
File metadata and controls
173 lines (151 loc) · 5.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
<?php
include_once MAPLE_DIR.'/includes/pear/HTTP/Request.php';
/**
* 他サイトからのデータ取得
*
* @package NetCommons
* @author Noriko Arai,Ryuji Masukawa
* @copyright 2006-2007 NetCommons Project
* @license http://www.netcommons.org/license.txt NetCommons License
* @project NetCommons Project, supported by National Institute of Informatics
* @access public
*/
class Request_Main {
/**
* コンストラクター
*
* @access public
*/
function Request_Main() {
}
/**
* 他サイトからデータ取得
* @param string url
* @return string html or boolean false
* @access public
*/
function getResponseHtml($url, $optParams=array()) {
$params = array('method' => 'GET');
$params = array_merge($params, $optParams);
if (!isset($params['timeout'])) {
$params['timeout'] = 30;
}
$req =& new HTTP_Request($url , $params);
$container =& DIContainerFactory::getContainer();
$configView =& $container->getComponent("configView");
$proxyConfigs = $configView->getConfigByCatid(_SYS_CONF_MODID, _SERVER_CONF_CATID);
if($proxyConfigs !== false) {
if($proxyConfigs['proxy_mode']['conf_value'] == _ON) {
$req->setProxy($proxyConfigs['proxy_host']['conf_value'], $proxyConfigs['proxy_port']['conf_value'], $proxyConfigs['proxy_user']['conf_value'], $proxyConfigs['proxy_pass']['conf_value']);
}
}
//$req->addHeader('User-Agent', $this->user_agent);
//$req->_readTimeout = array(0,1);
//$req->_timeout = 1;
$req->_allowRedirects = true;
$req->sendRequest() ;
$request_code = $req->getResponseCode();
if( $request_code == "200" ){
return $req->getResponseBody() ;
} else
return false;
}
/**
* 他サイトにデータを送信する
* @param string url
* @return string html or boolean false
* @access public
*/
function sendPost($url, $postData, $optParams=array()) {
$params = array('method' => 'POST');
$params = array_merge($params, $optParams);
if (!isset($params['timeout'])) {
$params['timeout'] = 30;
}
$req =& new HTTP_Request($url , $params);
$container =& DIContainerFactory::getContainer();
$configView =& $container->getComponent("configView");
$proxyConfigs = $configView->getConfigByCatid(_SYS_CONF_MODID, _SERVER_CONF_CATID);
if($proxyConfigs !== false) {
if($proxyConfigs['proxy_mode']['conf_value'] == _ON) {
$req->setProxy($proxyConfigs['proxy_host']['conf_value'], $proxyConfigs['proxy_port']['conf_value'], $proxyConfigs['proxy_user']['conf_value'], $proxyConfigs['proxy_pass']['conf_value']);
}
}
//$req->addHeader('User-Agent', $this->user_agent);
//$req->_readTimeout = array(0,1);
//$req->_timeout = 1;
$req->_allowRedirects = true;
$req->setMethod(HTTP_REQUEST_METHOD_POST);
foreach ($postData as $name=>$value) {
$req->addPostData($name, $value);
}
$req->sendRequest() ;
$request_code = $req->getResponseCode();
if( $request_code == "200" ){
return $req->getResponseBody() ;
} else
return false;
}
/*
function get_http_header($target)
{
// URIから各情報を取得
$info = (parse_url($target)) ? parse_url($target) : "";
if (!isset($info)) {
$ret = false;
return $ret;
}
$scheme = (isset($info['scheme'])) ? $info['scheme'] : "";
$host = (isset($info['host'])) ? $info['host'] : "";
$port = (isset($info['port'])) ? $info['port'] : "80"; // ポートが空の時はデフォルトの80
$path = (isset($info['path'])) ? $info['path'] : "";
// リクエストフィールドを制作
$msg_req = "HEAD " . $path . " HTTP/1.0\r\n";
$msg_req .= "Host: $host\r\n";
$msg_req .= "User-Agent: H2C/1.0\r\n";
$msg_req .= "\r\n";
// スキームがHTTPの時のみ実行
if ($scheme == 'http') {
$status = array();
// 指定ホストに接続。
if ($handle = @fsockopen($host, $port, $errno, $errstr, 1)) {
fputs ($handle, $msg_req);
if (socket_set_timeout($handle, 3)) {
$line = 0;
while(!feof($handle)) {
// 1行めはステータスライン
if($line==0) {
$temp_stat = explode(' ', fgets($handle, 4096));
$status['HTTP-Version'] = trim(array_shift($temp_stat));
$status['Status-Code'] = trim(array_shift($temp_stat));
$status['Reason-Phrase'] = trim(implode(' ', $temp_stat));
// 2行目以降はコロンで分割してそれぞれ代入
} else {
$temp_stat = explode(':', fgets($handle, 4096));
$name = array_shift( $temp_stat );
// 通常:の後に1文字半角スペースがあるので除去
$status[ $name ] = trim(substr(implode(':', $temp_stat), 1));
}
$line++;
}
} else {
$status['HTTP-Version'] = '---';
$status['Status-Code'] = '902';
$status['Reason-Phrase'] = "No Response";
}
fclose ( $handle );
} else {
$status['HTTP-Version'] = '---';
$status['Status-Code'] = '901';
$status['Reason-Phrase'] = "Unable To Connect";
}
} else {
$status['HTTP-Version'] = '---';
$status['Status-Code'] = '903';
$status['Reason-Phrase'] = "Not HTTP Request";
}
return $status;
}
*/
}
?>