我在Slim 3中设计了rest api,它将客户详细信息存储在MySQL db中。我正在使用Retrofit 1.9连接到webservice。我收到服务器错误500,其中同样的请求在POSTMAN中正常工作。
var mapper = Mappers.Xy<MeasureModel>()
.X(model => model.DateTime.Ticks) //use DateTime.Ticks as X
.Y(model => model.Value); //use the value property as Y
//The next code simulates data changes every 500 ms
Timer = new Timer
{
Interval = 1000
};
Timer.Tick += TimerOnTick;
R = new Random();
Timer.Start();
ChartValues.Add(new MeasureModel
{
DateTime = now,
Value = R.Next(0, 5)
});
接口:
//using retrofit
RestAdapter adapter = new RestAdapter.Builder().setEndpoint(Config.CUSTOMER_URL).build();
RegisterCustomer api = adapter.create(RegisterCustomer.class);
api.registerCustomer(custName.toString(),
phoneNumber.toString(),
address.toString(),
Config.API_KEY, new Callback<retrofit.client.Response>() {
@Override
public void success(retrofit.client.Response result, retrofit.client.Response response) {
BufferedReader reader = null;
String output = "";
try {
reader = new BufferedReader(new InputStreamReader(result.getBody().in()));
output = reader.readLine();
} catch (IOException e) {
e.printStackTrace();
}
Log.d("customer result",result.getBody()+"##"+result.getStatus() +"##" +response.getBody().toString());
}
@Override
public void failure(RetrofitError error) {
Log.d("customer save fail ",error.getMessage());
}
});
我的PHP代码。
public interface RegisterCustomer
{
@FormUrlEncoded
@POST("/customer")
public void registerCustomer(
@Field("cust_name") String cust_name,
@Field("phone") String phone,
@Field("address") String address,
@Field("apikey") String apikey,
Callback<Response> callback);
}