0
votes

Hi I want to create Repository with Artifactory JFROG Api,But I got 406 error code with api

I can run this json request over postman with selected application/json mime type

But I cant run over my c# code.What should I do in my .net code to use jfrog artifactory api?

{"key":"ArtifactRepoGroup3","rclass":"virtual","packageType":"nuget","description":"This repo created by"}

using (HttpClient client = new HttpClient()) { client.BaseAddress = new Uri(BaseAddress); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

............

HttpResponseMessage response = client.PutAsJsonAsync(puturi, value).Result; }

1

1 Answers

0
votes

I cant run PutAsJsonAsync method with standart application/json but I can do it use StringContent and embedded jfrog specific mime type into my content

         VirtualRepository repository = new VirtualRepository();
        repository.key = "ArtifactRepoGroup1";
        repository.packageType = "nuget";
        repository.rclass = "virtual";
        repository.description = "This repo created by ";

        var content = JsonConvert.SerializeObject(repository);

        var conent = new StringContent(content, Encoding.UTF8,
                            "application/vnd.org.jfrog.artifactory.repositories.VirtualRepositoryConfiguration+json");

....

            var response = client.PutAsync(uri, conent).Result;
            string b = response.Content.ReadAsStringAsync().Result;