Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLIENTS: Need a way to output HttpResponseMessage before deserializing #47

Open
LBoullosa opened this issue Sep 26, 2022 · 4 comments
Open

Comments

@LBoullosa
Copy link
Contributor

Hi!

I have a problem when posting a request to an endpoint. Deserializing the response causes

Unexpected character encountered while parsing value: <. Path '', line 0, position 0.

image

It´s curious if I run the post from Postman with the exact input json I retrieved the output json. It seems correct

image

So I don´t know what´s trying to deserialize.
I try to import all the RESTFulSense project to debug it without success because wrong references between NetStandard RESTFulSense project conflicts with my .Net6 project so not able to compile. I tried adding some Console.WriteLine on responseString inside DeserializeResponseContent but i don´t know why something it´s blocking the messages to console. I tried too some static Action to "listen" the value from my broker but MissingMethodException at runtime.

Any suggestion?

Thanks in advance!

@LBoullosa
Copy link
Contributor Author

I changed from using

TResponse respuesta = await this.apiClient.PostContentAsync<TRequest, TResponse>(relativeUrl, content);

to

HttpResponseMessage httpResponse = await this.httpClient.PostAsJsonAsync<TRequest>(relativeUrl, content);
string stringResponse= await httpResponse .Content.ReadAsStringAsync();
TResponse response = JsonConvert.DeserializeObject<TResponse>(stringResponse);

So, the service return the next json and the serialization with the same exact method RESTFulSense works

{"codResp":"1","mensaje":"A pre-reserva MDXXXXXXXXXXX001:ILLASRNdaB2ooEG9151 non existe","numeroVisitantes":null,"fechaIda":null,"fechaVuelta":null,"infoPrereservas":null}

So, I am wondering if the problem is when sending the request because serialization of "content" could be different because PostContentAsync vs PostAsJsonAsync and that difference causes the service to blow up and returns something different a json that ends on a deserialization problem.

I will research on this.

@jr-araujo
Copy link

@LBoullosa Could you share here the structure of the JSON and the similar content (removing the real one) you're using to do this test?

This way might be easier to identify the root cause of this issue and for other community developers to reproduce your error case-scenario.

@LBoullosa
Copy link
Contributor Author

@jr-araujo I am thinking if perhaps the problem is related with what happen on the OpenAI session with the mediatype. Tomorrow I will take a look at it and will try with the new version released a couple of days ago.
The json I sent has nothing special on it, the class representation for the request is exactly this

image

With RESTFulSense 2.9.0 fails.

Something is sent from RESTFulSense different from using directly the httpClient.PostAsJsonAsync. I guess reason makes the server responses not being a json, so the deserializer at client side blows up. That´s why I want to hook and see exactly what is being returned for the RESTFulSense request.

I could download source code and give it a try with my .NET 6 project, again.

As I said, tomorrow I will have more details, I need a VPN to consume the API Service, i haven´t it right now.

@LBoullosa
Copy link
Contributor Author

At least, I tested it with the new version.
I have to congratulate and communicate all of you, the issue I was having with 2.9 version it is resolved on the last version 2.12.
So it was related on how the body request was serializated when mediatype is "application/json". The same issue discovered during Standard.AI.OpenAI sessions.

@LBoullosa LBoullosa changed the title Clients: Need a way to output HttpResponseMessage before deserializing CLIENTS: Need a way to output HttpResponseMessage before deserializing Mar 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants