dapr / dapr/dotnet-sdk

Issue with HTTP call formatting in DaprClient

Open
#956 2 comments 0 reactions 0 assignees View on GitHub
area/client/invoke kind/bug
Dominant language
C#
Stars
1.2k
Forks
378
Avg merge
1d 22h
Merged PRs (30d)
5

Description

I am using DaprClient for HTTP calls.
I'm having an issue with the format of the response when getting the string of the response via a get request.

### My RPC (my-app):
`[HttpGet]`
`public IActionResult Test()`
`{`
` return Ok("my string text");`
`}`

### DaprClient Invoke 1:
`string str = await daprClient.InvokeMethodAsync(HttpMethod.Get, "my-app", "test");`
I got "**Dapr.Client.InvocationException**" exception:
_An exception occurred while invoking method: my-app on app-id: test._
And the InnerException "**System.Text.Json.JsonException**":
_\u00270xE6\u0027 is an invalid start of a value. Path: $ | LineNumber: 0 | BytePositionInLine: 0._

### DaprClient Invoke 2:
Next, I tried a more low-level call:
`var req = daprClient.CreateInvokeMethodRequest(HttpMethod.Get, "my-app", "test");`
`var res = await daprClient.InvokeMethodWithResponseAsync(req);`
`return Ok(new`
`{`
` a = res.StatusCode,`
` b = await res.Content.ReadAsStringAsync(),`
`});`
Then I got the result:
`{`
` "a": 200,`
` "b": "my string text"`
`}`
It can be seen that it responds in "text/plain" format. If it is "application/json", the value of b will be `"\"my string text\""`.

### Summarize:
I looked at the source code for "CreateInvokeMethodRequest" in "DaprClientGrpc.cs" and none of the HTTP calls explicitly specify "Accept" (eg: application/json). However, JSON serialization is declared in the annotation of the generic method. So not specifying the Accept header, is it "incomplete"? In the case of "my-app", it responds in "text/plain" format by default, which makes JSON formatting impossible.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.