相关文章推荐
逼格高的作业本  ·  AIX Toolbox for Open ...·  2 月前    · 
刚失恋的水煮肉  ·  curl ...·  1 月前    · 
耍酷的啄木鸟  ·  Imports - Post Import ...·  昨天    · 
大方的酸菜鱼  ·  Search Results | ...·  8 月前    · 
俊秀的勺子  ·  ruby on rails - ...·  1 年前    · 

I have to post this json data (data is generated in javascript and must be post to the enpoint from backend):

JSON.stringify(dataRest) is: {"Ds_MerchantParameters":"eyJEU19NRVJDSEFOVF9BTU9VTlQiOiI3Myw4NCIsIkRTX01FUkNIQU5UX0NVUlJFTkNZIjoiOTc4IiwiRFNfTUVSQ0hBTlRfTUVSQ0hBTlRDT0RFIjoiMzUyNDM0NDM1IiwiRFNfTUVSQ0hBTlRfT1JERVIiOiIwMDAwMDAwMDA3NjUiLCJEU19NRVJDSEFOVF9JRE9QRVIiOiIxODExNzViOTBjNDM2ZDNlZDQ3ODg4OWEyMjdjNjI2Yjc0MDBiOTEyIiwiRFNfTUVSQ0hBTlRfVEVSTUlOQUwiOiIxIiwiRFNfTUVSQ0hBTlRfVFJBTlNBQ1RJT05UWVBFIjoiMCJ9","Ds_Signature":"X5IoP/ssIy+8gBFbD9znLoz4dFOH/mWRjMCaE/8kq65XJJVLywT05wVXE4Fqbbo6","Ds_SignatureVersion":"HMAC_SHA256_V1"}

To this endpoint https://sis-t.redsys.es:25443/sis/rest/trataPeticionREST

Using RestSharp (v107) (or httpclient).

I post above data to my api LaunchRequest via ajax:

$.ajax({
    method: 'POST',
    url: localhost + 'api/Redsys/LaunchRequest',
    contentType: 'application/json',
    data: JSON.stringify(dataRest)
}).done(function (response) {
    console.log(response);
}).fail(function (error) {
    console.error(error.status + '\n' + error.responseText);

This is the api that receive the above data and launch request to the endpoint:

[HttpPost("LaunchRequest")]
public async Task<string> LaunchRequest(DataRest dataRest)
    string strDataRest = JsonConvert.SerializeObject(dataRest);
    var client = new RestClient("https://sis-t.redsys.es:25443/");
    var request = new RestRequest("sis/rest/trataPeticionREST", Method.Post);
    request.RequestFormat = DataFormat.Json;
    request.AddBody(strDataRest);
    var response = await client.ExecuteAsync(request);
    if (response.IsSuccessful)
        return response.Content;
        return response.ErrorMessage;

What is wrong in LaunchRequest api?

Thank you in advance for your help

I think one of my mistakes is serialize dataRest.

LaunchRequest should be like this:

[HttpPost("LaunchRequest")]
public async Task<string> LaunchRequest(DataRest dataRest)
    var client = new RestClient("https://sis-t.redsys.es:25443/");
    var request = new RestRequest("sis/rest/trataPeticionREST", Method.Post);
    request.RequestFormat = DataFormat.Json;
    request.AddBody(dataRest);
    var response = await client.ExecuteAsync(request);
    if (response.IsSuccessful)
        return response.Content;
        return response.ErrorMessage;

I don't know if the steps I follow in LaunchRequest are correct, but anyway I always get this error message:

A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. (sis-t.redsys.es:25443)

Thank you very much again for the help you can give me.

If you use the ASP.NET Core and the LaunchRequest is the MVC action method, please try to add [FromBody] attribute as follows:

public async Task<string> LaunchRequest([FromBody] DataRest dataRest)