35
Help us understand the problem. What are the problem?

More than 5 years have passed since last update.

posted at

updated at

PHPでPOST送信する方法

Qiita API経由でQiitaのtokenを取得するにあたって、PHPでPOST送信を行う方法を調べてみた。

下記のコードでいけたので、メモしておく。
$url_nameと$passwordを正しく設定してやるとtokenが返ってくると思います。

<?php
$url = "https://qiita.com/api/v1/auth";
$data = array(
    'url_name' => $url_name,
    'password' => $password
);
$content = http_build_query($data);
$options = array('http' => array(
    'method' => 'POST',
    'content' => $content
));
$contents = file_get_contents($url, false, stream_context_create($options));

参考URL:
http://blog.totalsoft.co.jp/archives/3847364.html
http://qiita.com/docs

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Sign upLogin
35
Help us understand the problem. What are the problem?