I have already searched the site about this error and so far I have not found something that solves my problem. I'm trying to use restsharp, but I'm getting an error when passing data to .json
My Page with the API
<?php
header('Content-type: application/json');
require_once("config/config.php");
$result = array('status' => 500, 'message' => "Internal error");
if (isset($_POST['login']) && isset($_POST['password']))
{
$login = $_POST['login'];
$password = $_POST['password'];
$uuid = 'Not Found';
if (validaUsuario($login, $password) == true)
{
$result['status'] ='42';
$result['message'] = 'Connected with success';
$result['user'] = 'Teste';
$result['level'] = '100';
echo json_encode($result);
return;
} else
{
$result['status'] =202;
$result['message'] = "Password or login incorrect";
$result['token'] = 123456789;
$result['level'] = 10;
echo json_encode($result);
return;
}
echo json_encode($result);
}
?>
My code:
public static void UserLogin(string user,string pass)
{
var client = new RestClient();
client.BaseUrl = new Uri("http://localhost/r_user.php");
var request = new RestRequest();
request.Method = Method.POST;
request.AddParameter("login", user);
request.AddParameter("password", pass);
IRestResponse response = client.Execute(request);
var content = response.Content;
dynamic res = JObject.Parse(content);
if (res.status == "42")
{
}
}
I get the following error:
Newtonsoft.Json.JsonReaderException: 'Unexpected character encountered while parsing value: . Path '', line 0, position 0.'
I'm getting the content like this: {"status":"42","message":"Connected with success","user":"Teste","level":"100"}