facebook twitter hatena line email

「Php/fuelphp/httprequest」の版間の差分

提供: 初心者エンジニアの簡易メモ
移動: 案内検索
(生jsonデータをpostしたい場合)
行21: 行21:
 
  print $response->status; // 200
 
  print $response->status; // 200
 
  print nl2br(print_r($response->body(),1)); // html
 
  print nl2br(print_r($response->body(),1)); // html
 +
 +
==request詳細取得==
 +
urlを取得、リダイレクトした場合は、その先のurlが表示される
 +
echo $request->response_info('url');
 +
 +
その他はこちら
 +
            [url] => http://www.hogehoge.com<br />
 +
            [content_type] => text/html; charset=UTF-8<br />
 +
            [http_code] => 200<br />
 +
            [header_size] => 910<br />
 +
            [request_size] => 100<br />
 +
            [filetime] => -1<br />
 +
            [ssl_verify_result] => 0<br />
 +
            [redirect_count] => 1<br />
 +
            [total_time] => 0.079887<br />
 +
            [namelookup_time] => 0.001401<br />
 +
            [connect_time] => 0.003478<br />
 +
            [pretransfer_time] => 0.00348<br />
 +
            [size_upload] => 0<br />
 +
            [size_download] => 50500<br />
 +
            [speed_download] => 632142<br />
 +
            [speed_upload] => 0<br />
 +
            [download_content_length] => 178<br />
 +
            [upload_content_length] => 0<br />
 +
            [starttransfer_time] => 0.06756<br />
 +
            [redirect_time] => 0.006192<br />
 +
            [redirect_url] => <br />
 +
            [primary_ip] => 210.129.120.44<br />
 +
            [certinfo] => Array<br />
 +
                (<br />
 +
                )<br />
 +
<br />
 +
            [primary_port] => 80<br />
 +
            [local_ip] => xxx.xxx.xxx.xxx<br />
 +
            [local_port] => 44409<br />

2015年10月26日 (月) 01:19時点における版

postサンプル

$params = array(
  'id' => 'hoge',
);
$request = \Request::forge($url, 'curl');
$request->set_method('post');
$request->set_params($params);
$request->execute();
$response = $request->response();
print $response->status; // 200
print $response->body(); // html

生jsonデータをpostしたい場合

$json = json_encode($params);
$request = \Request::forge($url, 'curl');
$request->set_method('post');
$request->set_mime_type('json');
$request->set_params($json);
$request->execute();
$response = $request->response();
print $response->status; // 200
print nl2br(print_r($response->body(),1)); // html

request詳細取得

urlを取得、リダイレクトした場合は、その先のurlが表示される

echo $request->response_info('url');

その他はこちら

           [url] => http://www.hogehoge.com
[content_type] => text/html; charset=UTF-8
[http_code] => 200
[header_size] => 910
[request_size] => 100
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 1
[total_time] => 0.079887
[namelookup_time] => 0.001401
[connect_time] => 0.003478
[pretransfer_time] => 0.00348
[size_upload] => 0
[size_download] => 50500
[speed_download] => 632142
[speed_upload] => 0
[download_content_length] => 178
[upload_content_length] => 0
[starttransfer_time] => 0.06756
[redirect_time] => 0.006192
[redirect_url] =>
[primary_ip] => 210.129.120.44
[certinfo] => Array
(
)

[primary_port] => 80
[local_ip] => xxx.xxx.xxx.xxx
[local_port] => 44409