Witajcie.
Właśnie próbuję przeredagować zapytanie z curl'a w terminalu: curl -u "user:passwd" https://api.github.com/authorizations
Zrobiłem coś takiego:
$url = 'https://api.github.com/authorizations/';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_USERAGENT, "Agent");
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 1);
curl_setopt($ch, CURLOPT_USERPWD, "user:passwd");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$content = curl_exec($ch);
curl_close($ch);
Niestety nie działa.
Mam dla porównania zapytanie w pythonie, które działa znakomicie:
GITHUB_API = 'https://api.github.com'
url = urljoin(GITHUB_API, 'authorizations')
payload = {}
res = requests.post(
url,
auth = (username, password),
data = json.dumps(payload),
)
j = json.loads(res.text)
Macie pomysł jak to ma wyglądać?