Skip to content

Instantly share code, notes, and snippets.

@ochim
Created June 10, 2016 10:13
Show Gist options
  • Save ochim/3ac1b40fcb097dc9d99af6d0d0c86cbe to your computer and use it in GitHub Desktop.
Save ochim/3ac1b40fcb097dc9d99af6d0d0c86cbe to your computer and use it in GitHub Desktop.
PHPでPOSTリクエスト
PHP でPOSTリクエスト
```
<?php
//
$baseurl = "https://xxx.co.jp";
$method = "POST";
$path = "/user/login";
//header
$header = array(
"Content-Type: application/json; charset=utf-8",
"Accept-Language:ja"
);
// POSTデータ
$data0 = array(
"login_flg" => "1",
"company_code" => "1001",
"user_cd_alas" => "1001",
"password" => "1001"
);
$data1 = array(
"login_flg" => "1",
"company_code" => "5002",
"user_cd_alas" => "5002",
"password" => "5002"
);
$data = json_encode($data0);
$url = $baseurl . $path;
$options = array("http" => array(
"method" => $method,
"header" => implode("\r\n", $header),
"content" => $data
));
$contents = file_get_contents($url, false, stream_context_create($options));
print $contents."\n";
//
$data = json_encode($data1);
$url = $baseurl . $path;
$options = array("http" => array(
"method" => $method,
"header" => implode("\r\n", $header),
"content" => $data
));
$contents = file_get_contents($url, false, stream_context_create($options));
print $contents."\n";
//
$path = "/user/endpoint";
$header = array(
"Content-Type: application/json; charset=utf-8",
"Accept-Language:ja",
"Cookie:JSESSIONID=19543b8f491596"
);
$data1 = array(
"device_id" => "9e1c3d62e62c7ebd31dc2180036a1d6fbade4494",
);
$data = json_encode($data1);
$url = $baseurl . $path;
$options = array("http" => array(
"method" => $method,
"header" => implode("\r\n", $header),
"content" => $data
));
$contents = file_get_contents($url, false, stream_context_create($options));
print $contents."\n";
//
$path = "/eanpi/report/disasters";
$header = array(
"Content-Type: application/json; charset=utf-8",
"Accept-Language:ja",
"Cookie:JSESSIONID=6c1c88d447808a"
);
$data1 = array("sequence_no"=>"0", "all_flg" => "0"
);
$data = json_encode($data1);
$url = $baseurl . $path;
$options = array("http" => array(
"method" => $method,
"header" => implode("\r\n", $header),
"content" => $data
));
$contents = file_get_contents($url, false, stream_context_create($options));
print $contents."\n";
?>
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment