2017-06-29 2 views
0

GitLab APIにマルチファイルコミットを送信しようとしています。RestSharp POST GitLab-APIでコミットします

私は承認を受けて、BadRequestという応答を得ています。 I私のJSONを検証してきましたが、私は、応答

でこれを取得しています "{" エラー ":" ブランチはcommit_messageが欠落している、欠けている、アクションが欠落している "}"

JSON

{ 
    "branch": "master", 
    "commit_message": "Ticket-27 6\/29\/2017 4:37:13 PM", 
    "author_name": "My Name", 
    "author_email": "[email protected]", 
    "actions": [{ 
      "action": "create", 
      "file_path": "procedures\/dbo.sp_SomeProc1.sql", 
      "content": "\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n-- =============================================\r\n-- Author:\t\t<,,Name>\r\n-- Create date: <Create Date,,>\r\n-- Description:\t<Description,,>\r\n-- =============================================\r\n\r\nCREATE PROCEDURE [dbo].[sp_SomeProc1] @ID int,@StartDate datetime\r\n\t-- Add the parameters for the stored procedure here\r\n\r\nAS\r\nBEGIN\r\n\r\n\tSET NOCOUNT ON;\r\n\tSELECT * FROM MyTable WHERE MEMBERID = @ID \r\n\t" 
     }, { 
      "action": "create", 
      "file_path": "procedures\/dbo.sp_SomeProc2.sql", 
      "content": "\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n-- =============================================\r\n-- Author:\t\t<,,Name>\r\n-- Create date: <Create Date,,>\r\n-- Description:\t<Description,,>\r\n-- =============================================\r\n\r\nCREATE PROCEDURE [dbo].[sp_SomeProc2] @ID int,@StartDate datetime\r\n\t-- Add the parameters for the stored procedure here\r\n\r\nAS\r\nBEGIN\r\n\r\n\tSET NOCOUNT ON;\r\n\tSELECT * FROM MyTable WHERE MEMBERID = @ID \r\n\t" 
     }, { 
      "action": "create", 
      "file_path": "procedures\/dbo.sp_SomeProc3.sql", 
      "content": "\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n-- =============================================\r\n-- Author:\t\t<,,Name>\r\n-- Create date: <Create Date,,>\r\n-- Description:\t<Description,,>\r\n-- =============================================\r\n\r\nCREATE PROCEDURE [dbo].[sp_SomeProc3] @ID int,@StartDate datetime\r\n\t-- Add the parameters for the stored procedure here\r\n\r\nAS\r\nBEGIN\r\n\r\n\tSET NOCOUNT ON;\r\n\tSELECT * FROM MyTable WHERE MEMBERID = @ID \r\n\t" 
     } 
    ] 
} 

私はその後"test"するコンテンツを変更しますが、私はRestSharpから信じている別のエラーを取得します。

  • StatusCode = 0
  • ErrorMessage = "Object reference not set to an instance of an object."

JSON

{ 
    "branch": "master", 
    "commit_message": "Ticket-27 6\/29\/2017 4:37:13 PM", 
    "author_name": "My Name", 
    "author_email": "[email protected]", 
    "actions": [{ 
      "action": "create", 
      "file_path": "procedures\/dbo.sp_SomeProc1.sql", 
      "content": "test" 
     }, { 
      "action": "create", 
      "file_path": "procedures\/dbo.sp_SomeProc2.sql", 
      "content": "test" 
     } 
    ] 
} 

そして最後に、私のC#コード:

RestRequest request = 
    new RestRequest([email protected]"api/v4/projects/{project.id}/repository/commits", Method.POST); 

request.Parameters.Add(new Parameter() { 
    ContentType = "application/json", 
    Type = ParameterType.RequestBody, 
    Value = commit 
}); 

request.Parameters.Add(new Parameter() { 
    Name = "PRIVATE-TOKEN", 
    Type = ParameterType.HttpHeader, 
    Value = ConfigurationManager.AppSettings["GitLabPrivateToken"] 
}); 

request.RequestFormat = DataFormat.Json; 

IRestResponse respone = _restClient.Execute(request); 

今、"file_path"はブランチには実際には存在しませんが、私は"create"のアクションを取っていたので、それは必要ではないと思いました。 StatusCode = 0

at RestSharp.RestClient.<ConfigureHttp>b__2f(Parameter p2) 
at System.Linq.Enumerable.All[TSource](IEnumerable`1 source, Func`2 predicate) 
at RestSharp.RestClient.ConfigureHttp(IRestRequest request, IHttp http) 
at RestSharp.RestClient.Execute(IRestRequest request, String httpMethod, Func`3 getResponse) 

答えて

0

EDIT スタックトレースは、だから、それは私のJSONリクエストパラメータのパラメータの名前はapplication/jsonなるために必要なことが判明しました。変更後、正常に動作しました。ここでは、最終的なC#コードは次のとおりです。

RestRequest request = 
    new RestRequest([email protected]"api/v4/projects/{project.id}/repository/commits", Method.POST); 

request.Parameters.Clear(); 

request.Parameters.Add(new Parameter() { 
    Name = "application/json", 
    ContentType = "application/json", 
    Type = ParameterType.RequestBody, 
    Value = commit 
}); 
request.Parameters.Add(new Parameter() { 
    Name = "PRIVATE-TOKEN", 
    Type = ParameterType.HttpHeader, 
    Value = ConfigurationManager.AppSettings["GitLabPrivateKey"] 
}); 

IRestResponse respone = _restClient.Execute(request); 

ので、小さな何かが時間のためにあなたが狂気運転する方法アメージング。

関連する問題