0

json を jboss サービスに投稿しようとしています。restSharpを使用して..私のコードは次のとおりです。

        RestClient client = new RestClient(baseURL);
        RestRequest authenticationrequest = new RestRequest();
        authenticationrequest.RequestFormat = DataFormat.Json;
        authenticationrequest.Method = Method.POST;
        authenticationrequest.AddParameter("text/json",                  authenticationrequest.JsonSerializer.Serialize(prequestObj), ParameterType.RequestBody);

そしてこれも試しました

        RestClient client = new RestClient(baseURL);
        RestRequest authenticationrequest = new RestRequest();
        authenticationrequest.RequestFormat = DataFormat.Json;
        authenticationrequest.Method = Method.POST;                           authenticationrequest.AddBody(authenticationrequest.JsonSerializer.Serialize(prequestObj));

しかし、どちらの場合も、私のサーバーはjsonが正しい形式ではないというエラーを出しています

4

2 に答える 2

0

JsonHelper を使用して、json を次のように準備してみてください。

 string jsonToSend = JsonHelper.ToJson(prequestObj);

その後

authenticationrequest.AddParameter("application/json; charset=utf-8", jsonToSend, ParameterType.RequestBody);
于 2013-04-23T11:12:01.350 に答える