私は次のようにサービス・スタックAPIにJsonServiceClientとパッチを実行しようとしている:のContent-Typeが「アプリケーション/ JSON-パッチ+ JSON」でなければなりませんJsonServiceClient ServiceStack
var patchRequest = new JsonPatchRequest
{
new JsonPatchElement
{
op = "replace",
path = "/firstName",
value = "Test"
}
};
_jsonClient.Patch<object>($"/testurl/{id}", patchRequest);
をしかし、私は取得しています次のエラー:
Content-Type must be 'application/json-patch+json'
エラーはクリアされています。 JsonServiceClientのリクエストを実行する前にコンテンツタイプを変更する方法はありますか?
これはServiceStack APIの要求POCOは以下のとおりです。
[Api("Partial update .")]
[Route("/testurl/{Id}”, "PATCH")]
public class PartialTest : IReturn<PartialTestRequestResponse>, IJsonPatchDocumentRequest,
IRequiresRequestStream
{
[ApiMember(Name = “Id”, ParameterType = "path", DataType = "string", IsRequired = true)]
public string Id { get; set; }
public Stream RequestStream { get; set; }
}
public class PartialTestRequestResponse : IHasResponseStatus
{
public ResponseStatus ResponseStatus { get; set; }
}
サービスの実装:私はMarvin.JsonPatch V 1.0.0ライブラリを使用してい
public object Patch(PartialTest request)
{
var dbTestRecord = Repo.GetDbTestRecord(request.Id);
if (dbTestRecord == null) throw HttpError.NotFound("Record not found.");
var patch =
(JsonPatchDocument<TestRecordPoco>)
JsonConvert.DeserializeObject(Request.GetRawBody(), typeof(JsonPatchDocument<TestRecordPoco>));
if (patch == null)
throw new HttpError(HttpStatusCode.BadRequest, "Body is not a valid JSON Patch Document.");
patch.ApplyTo(dbTestRecord);
Repo.UpdateDbTestRecord(dbTestRecord);
return new PartialTestResponse();
}
。
これはServiceStackのエラーではありません。あなたの投稿を更新して、ServiceStackサービスの実装を含めてください。 – mythz