I have GraphQL running on localhost (http://localhost:23061/graphql) and I'm trying to replicate the query I do in the UI directly but within C#. I have verified that the JSON package is correct on postman beforehand but whenever such package is attempted in C# it will just return a 500 error, I tried quite a few variations of this package (swapping " with ' as an example) but unfortunately all the same.
So the query I used on postman is {"query":"{goldBalance(address: "0xa49d64c31A2594e8Fb452238C9a03beFD1119963")}"} this returns just fine in postman.
When moving this to C# however;
static async System.Threading.Tasks.Task Main(string[] args)
{
var httpClient = new HttpClient();
var url = "http://localhost:23061/graphql";
var data = "{ \"query\":\"{goldBalance(address: \"0xa49d64c31A2594e8Fb452238C9a03beFD1119963\")}\"}";
var content = new StringContent(data.ToString(), Encoding.UTF8, "application/json");
content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
var result = httpClient.PostAsync(url, content).Result;
Console.WriteLine(result);
}
When this is ran, it will always return;
StatusCode: 500, ReasonPhrase: 'Internal Server Error', Version: 1.1, Content: System.Net.Http.HttpConnectionResponseContent, Headers:
{
Date: Tue, 30 Mar 2021 20:18:36 GMT
Server: Kestrel
Content-Length: 0
}
I thought initially that this could be a HTTPClient issue but WebRequest, so it is clearly an issue on my send somewhere.