0
I have looked here on the website about this error and so far I have not found anything to solve my problem. I’m trying to use restsharp, but I’m getting an error when passing the data to . json
My Page with 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")
{
}
}
Returns me the following error:
Newtonsoft.Json.JsonReaderException: 'Unexpected character encountered while parsing value: . Path '', line 0, position 0.'
I’m getting content like this : {"status":"42","message":"Connected with success","user":"Teste","level":"100"}
$result =(Object) ['status' => 500, 'message' => 'Internal error']; has tried to use so?
– Will
I tried but it didn’t work either @Will
– Rickafds
what is the error? your C# method waits
user
andpass
but you putlogin
andpassword
– Leandro Angelo
@Leandroangelo Obridado for the help,I managed to solve, posted the resolution of the problem
– Rickafds