2016-06-21 71 views
0

這是一個關於如何使用REST API和捲曲上傳到的Nexus文件:https://support.sonatype.com/hc/en-us/articles/213465818-How-can-I-programatically-upload-an-artifact-into-Nexus-如何使用RestSharp將文件上傳到Nexus?

下面是我的C#代碼,它返回一個完成的狀態,但文件沒有上傳。不知道缺少什麼。

public void uploadArtifact() 
    { 
     RestRequest request = new RestRequest("artifact/maven/content/", Method.POST); 
     request.RequestFormat = RestSharp.DataFormat.Json; 
     request.AddHeader("Content-Type", "x-www-form-urlencoded"); 
     request.AddParameter("r", "releases"); 
     request.AddParameter("hasPom", "false"); 
     request.AddParameter("p", "zip"); 
     request.AddParameter("e", "zip"); 
     request.AddParameter("g", "otpp.devops");   
     request.AddParameter("a", "githubSuspsendInactiveADAccounts"); 
     request.AddParameter("v", "1.0.1"); 
     request.AddFile("githubSuspsendInactiveADAccounts-1.0.1.zip", @"C:\\Temp\\Nexus\\githubSuspsendInactiveADAccounts-1.0.1.zip"); //Completed but not uploaded 

     IRestResponse response = this.restSharpAPI.Execute(this.client, request); 
     Console.WriteLine("Response received: {0}", response.ResponseStatus);   

    } 

回答

0

我做了這個工作,還沒有想出如何添加路徑:

request.AddFile("githubSuspsendInactiveADAccounts-1.0.1.zip", "githubSuspsendInactiveADAccounts-1.0.1.zip"); 
相關問題