47
50

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

file_get_contentsでPOSTデータ送信

Posted at
	private function __post_ file_get_contents()
	{
		$url = 'http://qiita.com/';

		// POSTデータ
		$data = array(
			"param1" => "1",
			"param2" => 2
		);
		$data = http_build_query($data, "", "&");

		// header
		$header = array(
			"Content-Type: application/x-www-form-urlencoded",
			"Content-Length: ".strlen($data)
		);

		$context = array(
			"http" => array(
				"method"  => "POST",
				"header"  => implode("\r\n", $header),
				"content" => $data
			)
		);

		$html = file_get_contents($url, false, stream_context_create($context));

		return html;
	}

47
50
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
47
50

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?