• Dear Pleskians! The Plesk Forum will be undergoing scheduled maintenance on Monday, 7th of July, at 9:00 AM UTC. The expected maintenance window is 2 hours.
    Thank you in advance for your patience and understanding on the matter.

Resolved 415 Unsupported Media Type

desaPax

New Pleskian
Server operating system version
Microsoft Windows Server 2022
Plesk version and microupdate number
Plesk Obsidian v18.0.62_build20240724.14 os_Windows 2012/2016/2019/2022
For a few days now, when I try to install LetsEncrypt certificates, I get the error 415 Unsupported Media Type only in that call. I have tried other calls and they don't give an error. It only gives it in that one.
I use C# to make the calls. I attach the code

private void InitializeClient()
{

apiClient = new HttpClient();
apiClient.BaseAddress = new Uri(hostUrl);
ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;
apiClient.DefaultRequestHeaders.Clear();
apiClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
ServicePointManager.MaxServicePointIdleTime = int.MaxValue;
var byteArray = Encoding.ASCII.GetBytes(string.Format("{0}:{1}", user, pass));
apiClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray));

}
//NO WORKS
public async Task<APIResult> InstalarRenvarSSL(string dominio)
{
var ls = new SSLParams();
List<string> @params = new List<string>();
@params.Add("--exec");
@params.Add("letsencrypt");
@params.Add("cli.php");
@params.Add("-d");
@params.Add(dominio);
if (dominio.StartsWith("www."))
{
@params.Add("-d");
@params.Add(dominio.Replace("www.",""));
}
@params.Add("-m");
@params.Add("[email protected]");
ls.@params = @params;
StringContent cont = new StringContent(JsonConvert.SerializeObject(ls));
using (HttpResponseMessage response = await apiClient.PostAsync("/api/v2/cli/extension/call", cont))
{

if (response.IsSuccessStatusCode)
{
var content = await response.Content.ReadAsStringAsync();
var result = JsonConvert.DeserializeObject<APIResult>(content);
return result;
}
else
throw new Exception(response.ReasonPhrase);
}
}

//THIS WORKS
public async Task<bool> ObtExtensiones()
{
using (HttpResponseMessage response = await apiClient.GetAsync("/api/v2/extensions"))
{
if (response.IsSuccessStatusCode)
{
var content = await response.Content.ReadAsStringAsync();
//var result = JsonConvert.DeserializeAnonymousType<>(content);
return true;
}
else
throw new Exception(response.ReasonPhrase);
}
}
 
Yes, I've seen that post, but that's not my case. In fact, I already send the application/json mime type in the calls.
Also, other calls such as listing the extensions in the /api/v2/extensions panel work perfectly.
Only the one that allows me to install SSL using LetsEncryp fails.
 
I've solved it now. It seems that you now have to indicate the data type in the string that is sent when making the request.

//NO WORKING
StringContent cont = new StringContent(JsonConvert.SerializeObject(ls));

//WORKS
StringContent cont = new StringContent(JsonConvert.SerializeObject(ls), Encoding.UTF8,"application/json");
 
Back
Top