<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Can't import a certificate via XML API using C# in General Topics</title>
    <link>https://live.paloaltonetworks.com/t5/general-topics/can-t-import-a-certificate-via-xml-api-using-c/m-p/583807#M116661</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm trying to import a certificate to a Palo Alto VM-50 via XML API with an App written in C# but I always get this error:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;&amp;lt;response status = 'error' code = '400'&amp;gt;&amp;lt;result&amp;gt;&amp;lt;msg&amp;gt;No file uploaded&amp;lt;/msg&amp;gt;&amp;lt;/result&amp;gt;&amp;lt;/response&amp;gt;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My C# code is below, I can't see where the problem is, if I use this curl command the file gets uploaded successfully:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;curl --insecure --header "Authorization:Basic myauth" -F "file=@testCA.crt" "https://10.16.66.229/api?type=import&amp;amp;category=certificate&amp;amp;certificate-name=TestCA&amp;amp;format=pem"&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any ideas?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;using System;
using System.IO;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;

namespace TestUploadPA
{
    internal class Program
    {
        static async Task Main(string[] args)
        {
            string url = "https://10.16.66.229/api/?type=import&amp;amp;category=certificate&amp;amp;certificate-name=TestCA&amp;amp;format=pem";
            string filePath = "testCA.crt";
            string username = "myuser";
            string password = "mypass";

            var handler = new HttpClientHandler
            {
                ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) =&amp;gt; true,
            };

            using (HttpClient client = new HttpClient(handler))
            {
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(Encoding.ASCII.GetBytes(username + ":" + password)));

                using (var formData = new MultipartFormDataContent())
                using (var fileContent = new ByteArrayContent(File.ReadAllBytes(filePath)))
                {
                    fileContent.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
                    formData.Add(fileContent, "file", Path.GetFileName(filePath));

                    HttpResponseMessage response = await client.PostAsync(url, formData);

                    if (response.IsSuccessStatusCode)
                    {
                        string content = await response.Content.ReadAsStringAsync();
                        Console.WriteLine($"XML result: {content}");
                    }
                    else
                    {
                        Console.WriteLine($"Error uploading file. Status code: {response.StatusCode}");
                    }
                }
            }
        }
    }
}
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 15 Apr 2024 23:57:36 GMT</pubDate>
    <dc:creator>kittcat</dc:creator>
    <dc:date>2024-04-15T23:57:36Z</dc:date>
    <item>
      <title>Can't import a certificate via XML API using C#</title>
      <link>https://live.paloaltonetworks.com/t5/general-topics/can-t-import-a-certificate-via-xml-api-using-c/m-p/583807#M116661</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm trying to import a certificate to a Palo Alto VM-50 via XML API with an App written in C# but I always get this error:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;&amp;lt;response status = 'error' code = '400'&amp;gt;&amp;lt;result&amp;gt;&amp;lt;msg&amp;gt;No file uploaded&amp;lt;/msg&amp;gt;&amp;lt;/result&amp;gt;&amp;lt;/response&amp;gt;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My C# code is below, I can't see where the problem is, if I use this curl command the file gets uploaded successfully:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;curl --insecure --header "Authorization:Basic myauth" -F "file=@testCA.crt" "https://10.16.66.229/api?type=import&amp;amp;category=certificate&amp;amp;certificate-name=TestCA&amp;amp;format=pem"&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any ideas?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;using System;
using System.IO;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;

namespace TestUploadPA
{
    internal class Program
    {
        static async Task Main(string[] args)
        {
            string url = "https://10.16.66.229/api/?type=import&amp;amp;category=certificate&amp;amp;certificate-name=TestCA&amp;amp;format=pem";
            string filePath = "testCA.crt";
            string username = "myuser";
            string password = "mypass";

            var handler = new HttpClientHandler
            {
                ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) =&amp;gt; true,
            };

            using (HttpClient client = new HttpClient(handler))
            {
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(Encoding.ASCII.GetBytes(username + ":" + password)));

                using (var formData = new MultipartFormDataContent())
                using (var fileContent = new ByteArrayContent(File.ReadAllBytes(filePath)))
                {
                    fileContent.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
                    formData.Add(fileContent, "file", Path.GetFileName(filePath));

                    HttpResponseMessage response = await client.PostAsync(url, formData);

                    if (response.IsSuccessStatusCode)
                    {
                        string content = await response.Content.ReadAsStringAsync();
                        Console.WriteLine($"XML result: {content}");
                    }
                    else
                    {
                        Console.WriteLine($"Error uploading file. Status code: {response.StatusCode}");
                    }
                }
            }
        }
    }
}
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 15 Apr 2024 23:57:36 GMT</pubDate>
      <guid>https://live.paloaltonetworks.com/t5/general-topics/can-t-import-a-certificate-via-xml-api-using-c/m-p/583807#M116661</guid>
      <dc:creator>kittcat</dc:creator>
      <dc:date>2024-04-15T23:57:36Z</dc:date>
    </item>
    <item>
      <title>Re: Can't import a certificate via XML API using C#</title>
      <link>https://live.paloaltonetworks.com/t5/general-topics/can-t-import-a-certificate-via-xml-api-using-c/m-p/584515#M116754</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I managed to figured out what was wrong: the boundary in the multipart/form-data content-type header was being double quoted. I added some code to remove the quotes and I was able to import the certificate to the Palo Alto firewall successfully.&lt;/P&gt;</description>
      <pubDate>Mon, 22 Apr 2024 16:38:45 GMT</pubDate>
      <guid>https://live.paloaltonetworks.com/t5/general-topics/can-t-import-a-certificate-via-xml-api-using-c/m-p/584515#M116754</guid>
      <dc:creator>kittcat</dc:creator>
      <dc:date>2024-04-22T16:38:45Z</dc:date>
    </item>
  </channel>
</rss>

