1

I recieve error from outer api, I think there is something wrong with my generated json content because when I'm sending the same data from postman, I get correct response.

Is there a way to preview what json will be generated from JsonContent? I have a http client method:

public async Task<ResponseDto> UploadAsync(RequestDto model, CancellationToken cancellationToken)
{
    var requestUri = HttpHelper.BuildUri(uri.UPLOAD);    
    JsonContent content = JsonContent.Create(model);  //<= how read that JsonContent   
    /* there is not problems
    var response = await _client.PostAsync(requestUri, content, cancellationToken);

    string responseContent = await response.Content.ReadAsStringAsync(cancellationToken);

    return JsonSerializer.Deserialize<ResponseDto>(responseContent)
        ?? throw new HttpRequestException(responseContent);*/
}
TryHard
  • 125
  • 9
  • I'd expect you'd need to call `.SerializeToStream` to a `MemoryStream` and then convert that to a `string`. Or use a tool like Telerik's Fiddler to capture the request. I looks like System.Text.Json is used internally, so perhaps try just serializing it with that to start with to see if anything obvious if wrong. – ProgrammingLlama Dec 19 '22 at 05:50
  • 1
    Alternatively you could serialize your object to a string, log that, then use `StringContent` to post it as explained [here](https://stackoverflow.com/a/23586477/9363973). P.S alternatively to Fiddler you could also use Wireshark since it's free. – MindSwipe Dec 19 '22 at 07:15

0 Answers0