Deleted articles cannot be recovered. Draft of this article would be also deleted. Are you sure you want to delete this article?

PHPでのPOST送信には大まかに以下の様な4パターンほどの方法があります。 file_get_contents fopen fsockopen curl ただし、fopenに関してはfile_get_contentsとほぼ同じ様な処理なので、こういった方法もあるという参考程度にしてください。 簡単な送信であればfile_get_contentsを使う方法がベターです。 通信量が多い場合や、重い処理の場合はcURLを使うと良いです。 file_get_contentsを使った方法 $url = 'http://cppe.hol.es/post.php'; $data = array( 'msg' => 'メッセージ', ); $context = array( 'http' => array( 'method' => 'POST', 'header' => implode("\r\n",
// 初期設定 $API_ID = 'YOUR API ACCESS ID'; $API_PASSWORD = 'YOUR API ACCESS PASSWORD'; $API_VERSION = '1.0'; $API_ENDPOINT_URI = 'http://foo.var/api'; $data = array( "api_id" => $API_ID, "api_pass_hash" => md5($API_PASSWORD . time()), "version" => $API_VERSION, "condition" => 'paid' ); // postで接続 $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $API_ENDPOINT_URI); curl_setopt($ch, CURLOPT_POST, true)
$ch = curl_init(); curl_setopt_array($ch, [ CURLOPT_URL => 'http://hoge.com/fuga', CURLOPT_RETURNTRANSFER => true, CURLOPT_POST => true, CURLOPT_POSTFIELDS => http_build_query(['hoge' => 'fuga']), ]); $response = curl_exec($ch); curl_close($ch); 正解は、http_build_query するだけ! なんで? 一番の問題は、どちらのコードも動いてしまうこと。ただ、 bad.php はすごく時間がかかるので、やっちゃだめ。 headerを見てみると、good.php は Content-Type: application/x-www-form-urle
Swaggerとは Swaggerは言語に依存しないREST APIのインターフェース仕様とそのツール群を指す。 Swaggerの仕様に沿ってAPIを定義することで、人間が理解可能で、コンピューターにも解析可能なAPI仕様書となる。 引用:http://d.hatena.ne.jp/takeR/20151207/1449469957 らしいです。 ともあれ導入 環境 CentOS 6.5 x86_64 PHP環境(PHP5.5、Nginx1.8) CodeIgniter3.0.6 composerインストール $ curl -sS https://getcomposer.org/installer | php All settings correct for using Composer Downloading 1.0.0... Composer successfully installe
#概要 SlackのWebhookを利用して、API経由でメッセージをポストする。 ささっとPHPで試したい方や、botを作りたい方向け。 ご参考になれば。 #1.Webhookの設定 こちらより、「Post to Channel」に投稿先チャネル名を入力して「Add Incoming WebHooks integration」をクリック。 生成されたWebhook URLをメモる。 #2.Webhookが正常に使えるか確認 下記コマンドで投稿できるか確認する。 URL部分には、1.で作成したWebhook URLを指定する。 $ curl -X POST "https://hooks.slack.com/services/XXX/XXX/XXX" -d 'payload={ "channel": "#general", "username": "my_bot", "text": "tes
<?php $url = "http://www.yahoo.co.jp/"; $ch = curl_init(); // はじめ //オプション curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $info = curl_getinfo($ch);//この関数で取得 curl_close($ch); //終了 var_dump($info); >> array(22) { ["url"]=> string(23) "http://www.yahoo.co.jp/" ["content_type"]=> NULL ["http_code"]=> int(0) ["header_size"]=> int(0) ["request_size"]=> int(0) ["file
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く