kopia lustrzana https://github.com/newroco/mail2deck
Merge pull request #7 from bpehrs11/Fix-DeckClass-PHP_Curl-Issues
More explicitly handle the HTTP request methods with PHP cURLpull/12/head
commit
6987d50db7
|
@ -6,30 +6,31 @@ class DeckClass {
|
||||||
|
|
||||||
$headers = [
|
$headers = [
|
||||||
"OCS-APIRequest: true"
|
"OCS-APIRequest: true"
|
||||||
];
|
];
|
||||||
if ($request !== '') {// adding attachments doesn't support Content-Type: application/json.
|
|
||||||
array_push($headers, "Content-Type: application/json");
|
// set CURLOPTs commmon to all HTTP methods
|
||||||
$options = [
|
$options = [
|
||||||
CURLOPT_USERPWD => NC_USER . ":" . NC_PASSWORD,
|
CURLOPT_USERPWD => NC_USER . ":" . NC_PASSWORD,
|
||||||
CURLOPT_URL => $endpoint,
|
CURLOPT_URL => $endpoint,
|
||||||
CURLOPT_CUSTOMREQUEST => $request,
|
CURLOPT_RETURNTRANSFER => true,
|
||||||
CURLOPT_POST => true,
|
CURLOPT_SSLVERSION => "all",
|
||||||
CURLOPT_RETURNTRANSFER => true,
|
];
|
||||||
CURLOPT_POSTFIELDS => json_encode($data),
|
|
||||||
CURLOPT_HTTPHEADER => $headers,
|
// set HTTP request specific headers and options/data
|
||||||
CURLOPT_SSLVERSION => "all",
|
if ($request == '') {// an empty request value is used for attachments
|
||||||
];
|
// add data without JSON encoding or JSON Content-Type header
|
||||||
} else {
|
$options[CURLOPT_POST] = true;
|
||||||
$options = [
|
$options[CURLOPT_POSTFIELDS] = $data;
|
||||||
CURLOPT_USERPWD => NC_USER . ":" . NC_PASSWORD,
|
} elseif ($request == "POST") {
|
||||||
CURLOPT_URL => $endpoint,
|
array_push($headers, "Content-Type: application/json");
|
||||||
CURLOPT_POST => true,
|
$options[CURLOPT_POST] = true;
|
||||||
CURLOPT_RETURNTRANSFER => true,
|
$options[CURLOPT_POSTFIELDS] = json_encode($data);
|
||||||
CURLOPT_POSTFIELDS => $data,
|
} elseif ($request == "GET") {
|
||||||
CURLOPT_HTTPHEADER => $headers,
|
array_push($headers, "Content-Type: application/json");
|
||||||
CURLOPT_SSLVERSION => "all",
|
}
|
||||||
];
|
|
||||||
}
|
// add headers to options
|
||||||
|
$options[CURLOPT_HTTPHEADER] = $headers;
|
||||||
curl_setopt_array($curl, $options);
|
curl_setopt_array($curl, $options);
|
||||||
|
|
||||||
$response = curl_exec($curl);
|
$response = curl_exec($curl);
|
||||||
|
|
Ładowanie…
Reference in New Issue