Reputation: 1
I want to add a data for a json in openbravo, but the response is Null
This is for a app in xamarin to use Openbravo webservice
public void PostDataProyInf()
{
string urlBase = servInf + "/org.openbravo.service.json.jsonrest/cpm_daily_serv_rep";
IRestClient clients = new RestClient(urlBase);
clients.Authenticator = new HttpBasicAuthenticator(USname, USpass);
IRestRequest request = new RestRequest(Method.POST);
request.RequestFormat = DataFormat.Json;
request.AddHeader("Content-Type", "application/json");
//request.AddHeader("Accept", "*/*");
DateTime date = new DateTime();
date = DateTime.Now;
date.ToString("yyyy-MM-ddThh:mm:ss-hh:mm");
string workingT = Horas().ToString() + " " + "hour(s)" + " " + Minutes().ToString() + " min(s)";
var daily = " { \"data\": { \"_identifier\":\"" + proytS.Text + "\", \"_entityName\":\"cpm_daily_serv_rep\", \"$ref\":\"cpm_daily_serv_rep\", \"id\":\" \", \"client\":\"A9D216F4A8894012A48E168268A3D6C9\", \"client$_identifier\":\"Geosoft\", \"organization\":\"F14745C58DC74BA38A0F0C85A3C12E74\", \"organization$_identifier\":\"Geosoft Escencial\", \"active\":true, \"creationDate\":\"" + date.ToString() + "\", \"createdBy\":\"" + IdUser + "\", \"createdBy$_identifier\":\"" + USname + "\", \"updated\":\"" + date.ToString() + "\", \"updatedBy\":\"" + IdUser + "\", \"updatedBy$_identifier\":\"" + USname + "\", \"equipInstCctv\":" + eqCCTV.Checked + ", \"equipInstContAcc\":" + eqContAcc.Checked + ", \"equipInstDetSuspInc\":" + eqIncend.Checked + ", \"equipInstTelec\":" + eqTelec.Checked + ", \"equipInstElecGnral\":" + eqEleG.Checked + ", \"equipInstMatGnral\":" + eqMatGen.Checked + ", \"equipInstGnral\":" + eqGeneral.Checked + ", \"soporteria\":" + soport.Checked + ", \"canalizacion\":" + canal.Checked + ", \"cableado\":" + cableado.Checked + ", \"pruebas\":" + prueba.Checked + ", \"etiquetado\":" + etiquet.Checked + ", \"equipo\":" + equipo.Checked + ", \"project\":\"" + IdTempProy + "\", \"project$_identifier\":\"" + proytS.Text + "\", \"actvGeofDesc\":\"" + actEmpInfo.Text + "\", \"actvClientDesc\":\"" + actEmpInfo.Text + "\", \"retrabajos\":\"" + retrabS.Text + "\", \"otros\":null, \"notasMatFalt\":\"" + matFalInfo.Text + "\", \"tiempo\":0, \"cantInstSop\":null, \"cantInstCab\":null, \"cantInstPruebas\":null, \"cantInstEtiq\":null, \"cantInstEquipo\":null, \"cantInstCan\":null, \"workArea\":\"" + areTraInfo.Text + "\", \"currentDate\":\"" + date.ToString() + "\", \"entryDate\":\"" + fechaIniInfo.Text + "\", \"oUTDate\":\"" + fechaFinInfo.Text + "\", \"entryHour\":\"" + horaIniInfo.Text + "\", \"oUTHour\":\"" + horaFinInfo.Text + "\", \"expenseLine\":null, \"expenseLine$_identifier\":null, \"activity\":\"" + activiS.Text + "\", \"meetingClients\":" + junta.Checked + ", \"lifting\":false, \"supervision\":" + superv.Checked + ", \"engineeringDevelopment\":" + desIng.Checked + ", \"image\":null, \"image$_identifier\":null, \"workingTime\":\"" + workingT + "\", \"importServicesProject\":null, \"cuopgCreateInstallations\":null, \"projectPhase\":null, \"addtools\":null, \"recordTime\":null}}" ;
//string jsonesca = JsonConvert.SerializeObject(daily);
request.AddParameter("application/json", daily, ParameterType.RequestBody);
//request.AddJsonBody(daily);
IRestResponse resp = clients.Execute(request);
var content = resp.Content; // raw content as string
if (resp.StatusCode == HttpStatusCode.OK)
{
Toast.MakeText(this.Context, resp.Content, ToastLength.Long).Show();
}
else
{
Toast.MakeText(this.Context, "Not Conection Response!!!", ToastLength.Long).Show();
}
}
I expect a correct response from the webservice.
Upvotes: 0
Views: 68