2017-09-19 36 views
0

您好我想与Artifactory的JFROG API来创建库,但我得到了与APIJFROG版本库的创建与阿比

406错误代码,我可以运行在与选定的应用/ JSON的MIME类型邮递员JSON请求

但我无法运行我的C#代码。我应该如何在我的.net代码中使用jfrog artifactory api?

{ “键”: “ArtifactRepoGroup3”, “rclass”: “虚拟”, “packageType”: “的NuGet”, “描述”: “这回购通过创建”}

使用(HttpClient的客户端= new HttpClient()) client.BaseAddress = new Uri(BaseAddress); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(“application/json”));

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

HttpResponseMessage响应= client.PutAsJsonAsync(puturi, 值)。结果; }

回答

0

我不能运行PutAsJsonAsync方法与非标准应用程序/ JSON的,但我能做到这一点使用的StringContent和嵌入式jfrog特定的MIME类型到我的内容

  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;