The code that sends the request from MobileLogin.cs
is this:
private async static Task<MoralisLoginTokenResponse> RequestLoginToken(string moralisServerUrl, string applicationId)
{
MoralisLoginTokenResponse result = null;
MoralisLoginTokenRequest payload = new MoralisLoginTokenRequest()
{
_ApplicationId = applicationId
};
string data = JsonConvert.SerializeObject(payload);
using (HttpClient client = new HttpClient())
{
client.BaseAddress = new Uri(moralisServerUrl);
// Add an Accept header for JSON format.
client.DefaultRequestHeaders.Accept.Add(
new MediaTypeWithQualityHeaderValue("application/json"));
StringContent content = new StringContent(data);
// List data response.
HttpResponseMessage response = client.PostAsync(TOKEN_REQUEST_URL, content).Result; // Blocking call! Program will wait here until a response is received or a timeout occurs.
if (response.IsSuccessStatusCode)
{
// Parse the response body.
string responseBody = await response.Content.ReadAsStringAsync();
result = JsonConvert.DeserializeObject<MoralisLoginTokenResponse>(responseBody);
}
}
return result;
}
}
When execution reaches the check for whether it was successful or not:
client
{System.Net.Http.HttpClient}
BaseAddress: {https://ymg268vhppjv.usemoralis.com:2053/server}
DefaultRequestHeaders: {Accept: application/json\r\n}
MaxResponseContentBufferSize: 2147483647
Timeout: {00:01:40}
base_address: {https://ymg268vhppjv.usemoralis.com:2053/server}
buffer_size: 2147483647
cts: {System.Threading.CancellationTokenSource}
disposeHandler: true
disposed: false
handler: {System.Net.Http.HttpClientHandler}
headers: {Accept: application/json\r\n}
timeout: {00:01:40}
content
{System.Net.Http.StringContent}
Headers: {Content-Type: text/plain; charset=utf-8\r\nContent-Length: 61\r\n}
LoadedBufferLength: null
buffer: null
content: {byte[61]}
count: 61
disposed: false
headers: {Content-Type: text/plain; charset=utf-8\r\nContent-Length: 61\r\n}
offset: 0
stream: null
data
"{\"_ApplicationId\":\"UzNkJCH6fPfgEQeCOQhfzAtIbLlAbEDbpN7g4oqa\"}"
response
{StatusCode: 400, ReasonPhrase: 'Bad Request', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:\r\n{\r\nDate: Sat, 05 Feb 2022 08:44:38 GMT\r\nConnection: keep-alive\r\nX-Powered-By: Express\r\nAccess-Control-Allow-Origin: *\r\nAccess-Control-Allow-Methods: GET,PUT,POST,DELETE,OPTIONS\r\nAccess-Control-Allow-Headers: X-Parse-Master-Key, X-Parse-REST-API-Key, X-Parse-Javascript-Key, X-Parse-Application-Id, X-Parse-Client-Version, X-Parse-Session-Token, X-Requested-With, X-Parse-Revocable-Session, X-Parse-Request-Id, Content-Type, Pragma, Cache-Control, X-Parse-Installation-Id\r\nAccess-Control-Expose-Headers: X-Parse-Job-Status-Id, X-Parse-Push-Status-Id\r\nETag: W/\"3a-0JTlHXO2pC/ju0QshHRxP75EkI0\"\r\nCF-Cache-Status: DYNAMIC\r\nExpect-CT: max-age=604800, report-uri=\"https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct\"\r\nServer: cloudflare\r\nCF-RAY: 6d8adba458f33983-MAA\r\nContent-Type: application/json; charset=utf-8\r\nContent-Length: 58\r\n}}
Content: {System.Net.Http.StreamContent}
Headers: {Date: Sat, 05 Feb 2022 08:44:38 GMT\r\nConnection: keep-alive\r\nX-Powered-By: Express\r\nAccess-Control-Allow-Origin: *\r\nAccess-Control-Allow-Methods: GET,PUT,POST,DELETE,OPTIONS\r\nAccess-Control-Allow-Headers: X-Parse-Master-Key, X-Parse-REST-API-Key, X-Parse-Javascript-Key, X-Parse-Application-Id, X-Parse-Client-Version, X-Parse-Session-Token, X-Requested-With, X-Parse-Revocable-Session, X-Parse-Request-Id, Content-Type, Pragma, Cache-Control, X-Parse-Installation-Id\r\nAccess-Control-Expose-Headers: X-Parse-Job-Status-Id, X-Parse-Push-Status-Id\r\nETag: W/\"3a-0JTlHXO2pC/ju0QshHRxP75EkI0\"\r\nCF-Cache-Status: DYNAMIC\r\nExpect-CT: max-age=604800, report-uri=\"https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct\"\r\nServer: cloudflare\r\nCF-RAY: 6d8adba458f33983-MAA\r\n}
IsSuccessStatusCode: false
ReasonPhrase: "Bad Request"
RequestMessage: {Method: POST, RequestUri: 'https://ymg268vhppjv.usemoralis.com:2053/server/requestLoginToken', Version: 1.1, Content: System.Net.Http.StringContent, Headers:\r\n{\r\nAccept: application/json\r\nContent-Type: text/plain; charset=utf-8\r\nContent-Length: 61\r\n}}
StatusCode: BadRequest
Version: {1.1}
disposed: false
headers: {Date: Sat, 05 Feb 2022 08:44:38 GMT\r\nConnection: keep-alive\r\nX-Powered-By: Express\r\nAccess-Control-Allow-Origin: *\r\nAccess-Control-Allow-Methods: GET,PUT,POST,DELETE,OPTIONS\r\nAccess-Control-Allow-Headers: X-Parse-Master-Key, X-Parse-REST-API-Key, X-Parse-Javascript-Key, X-Parse-Application-Id, X-Parse-Client-Version, X-Parse-Session-Token, X-Requested-With, X-Parse-Revocable-Session, X-Parse-Request-Id, Content-Type, Pragma, Cache-Control, X-Parse-Installation-Id\r\nAccess-Control-Expose-Headers: X-Parse-Job-Status-Id, X-Parse-Push-Status-Id\r\nETag: W/\"3a-0JTlHXO2pC/ju0QshHRxP75EkI0\"\r\nCF-Cache-Status: DYNAMIC\r\nExpect-CT: max-age=604800, report-uri=\"https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct\"\r\nServer: cloudflare\r\nCF-RAY: 6d8adba458f33983-MAA\r\n}
reasonPhrase: "Bad Request"
statusCode: BadRequest
version: null
Since the response is bad, the return value of this result is null, which propagates over to LogIn
, causing it to in turn return null.