Hello, I'm having trouble converting a PHP API to be used in C #, I can connect to the API but I can not send data, could anyone help me?
Follow the PHP API:
$process = curl_init("URL API");
curl_setopt($process, CURLOPT_USERPWD, "USUARIO:SENHA");
curl_setopt($process, CURLOPT_TIMEOUT, 30);
curl_setopt($process, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($process, CURLOPT_POST, true);
curl_setopt($process, CURLOPT_POSTFIELDS, array(
"establishment" => $establishment,
"username" => $usuario,
"password" => $senha,
"name" => $nome,
"email" => $email,
"cpf" => $cpf,
"login_expiration" => $expirarLogin,
"profile_id" => $perfil
));
if(json_decode(curl_exec($process)) === false){
return FALSE;
}else{
return TRUE;
}
Here's what I've been able to do so far using C #:
using RestSharp;
var cookie = new CookieContainer();
var client = new RestClient("URL API") {
Authenticator = new HttpBasicAuthenticator("USUARIO", "SENHA"),
CookieContainer = cookie
};
var request = new RestRequest(Method.POST);
//var process = new RestClient(Method.POST);
//request.AddParameter(""", "projectID=729-11230-1", ParameterType.RequestBody);
//request.AddParameter("application/x-www-form-urlencoded", "name=Example backlog item 1", ParameterType.RequestBody);
//request.AddParameter("application/x-www-form-urlencoded", "establishment=sesc_new", ParameterType.GetOrPost);
//request.AddParameter("application/x-www-form-urlencoded", "username=user", ParameterType.GetOrPost);
//request.AddParameter("application/x-www-form-urlencoded", "password=senha", ParameterType.GetOrPost);
//request.AddParameter("application/x-www-form-urlencoded", "name=Teste API Sharp", ParameterType.GetOrPost);
//request.AddParameter("application/x-www-form-urlencoded", "email=email", ParameterType.GetOrPost);
//request.AddParameter("application/x-www-form-urlencoded", "cpf=cpf", ParameterType.GetOrPost);
//request.AddParameter("application/x-www-form-urlencoded", "login_expiration=2018-07-20 23:59:59", ParameterType.GetOrPost);
//request.AddParameter("application/x-www-form-urlencoded", "profile_id=4080", ParameterType.GetOrPost);
IRestResponse response = client.Execute(request);
MessageBox.Show(response.Content);
I can make the connection, but now I do not know how to send the information to the API from C #.