Answer the question
In order to leave comments, you need to log in
Php, json, urlencode - don't understand?
Hello.
One hosting has its own api - I screwed it up and everything seems to be OK but (!)
When the server sends an error report (for example, because an address with the same name already exists, I get the following message "{"status":"error" ,"message":"\u041f\u043e\u0447\u0442\..." \u041f\
u043e
\u0447\u0442\...
is urlencoded UTF-8 encoded text. this API is written:
The response to a POST request is always returned in UTF-8 encoding. Can be returned in JSON or XML format. The documentation only covers examples in JSON format.
The response always contains a status field, which can be error or success.
error: means that an error occurred while trying to execute the request. In this case, a detailed description of the error will be returned in the message field.
{"status":"error","message":"A mailbox named test already exists."}
success: The request was successful. In this case, depending on the operation performed, the server may return additional data in the data field.
{"status":"success","data":"219493"}
<?php
$fields = array(
'auth_login' => "moi_login",
'auth_token' => "moi_token",
'class' => "hosting_mailbox",
'method' => "create",
'account' => "moi_acc",
'mailbox' => $_POST['mailbox'],
'password' => $_POST['password'],
);
$fields_string = "";
foreach($fields as $key => $value) {
$fields_string .= $key.'='.urlencode($value).'&';
}
rtrim($fields_string, '&');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://HOSTING/api.php");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, count($fields));
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
$response = curl_exec($ch);
curl_close($ch);
echo "Ответ на Ваш запрос: ".$response;
?>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question