public class MaterialSupportapi extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... params) {
MaterialJson JSONOBJECT = new MaterialJson();
name = (EditText) findViewById(R.id.edt_name);
mobile = (EditText) findViewById(R.id.edt_contactnumber);
street = (EditText) findViewById(R.id.edt_address1);
city = (EditText) findViewById(R.id.edt_address2);
state = (EditText) findViewById(R.id.edt_address3);
zipcode = (EditText) findViewById(R.id.edt_address4);
day=(Spinner)findViewById(R.id.spinner1_Day);
month = (Spinner) findViewById(R.id.spinner2_month);
time_from = (Spinner) findViewById(R.id.spinner3_time_from);
time_to = (Spinner) findViewById(R.id.spinner4_time_to);
JSONOBJECT.setName(name.getText().toString());
JSONOBJECT.setMobile(mobile.getText().toString());
JSONOBJECT.setStreet(street.getText().toString());
JSONOBJECT.setCity(city.getText().toString());
JSONOBJECT.setState(state.getText().toString());
JSONOBJECT.setZipcode(zipcode.getText().toString());
JSONOBJECT.setDay(day.getSelectedItem().toString());
JSONOBJECT.setMonth(month.getSelectedItem().toString());
JSONOBJECT.setTimeFrom(time_from.getSelectedItem().toString());
JSONOBJECT.setTimeTo(time_to.getSelectedItem().toString());
JSONObject obj = new JSONObject();
try {
obj.put("name",JSONOBJECT.getName());
obj.put("mobile",JSONOBJECT.getMobile());
obj.put("day",JSONOBJECT.getDay());
obj.put("month",JSONOBJECT.getMonth());
obj.put("time_from",JSONOBJECT.getTimeFrom());
obj.put("time_to",JSONOBJECT.getTimeTo());
obj.put("street",JSONOBJECT.getStreet());
obj.put("city",JSONOBJECT.getCity());
obj.put("state",JSONOBJECT.getState());
obj.put("zipcode",JSONOBJECT.getZipcode());
// obj.put("type",JSONOBJECT.getType());
} catch (JSONException e) {
e.printStackTrace();
}
//Toast.makeText(this, obj.toString(), Toast.LENGTH_LONG).show();
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpPost httput = new HttpPost("https://vaananba.herokuapp.com/api/materialsupport");
StringEntity se = null;
try {
se = new StringEntity(obj.toString());
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
httput.setEntity(se);
httput.setHeader("content-type", "application/json");
int a = 0;
try {
HttpResponse resp = httpclient.execute(httput);
/*a = resp.getStatusLine().getStatusCode();
return a;*/
String responseBody = EntityUtils.toString(resp.getEntity());
//a = resp.getStatusLine().getStatusCode();
return responseBody.toString();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(String result) {
//TextView aa= (TextView)findViewById(R.id.textView3);
//aa.setText(result);
// Button submit = (Button) findViewById(R.id.btn_iamsupport);
//submit.setText(result);
Toast.makeText(MaterialSupport.this, result, Toast.LENGTH_LONG).show();
//Toast.makeText(IamSupport.this, result, Toast.LENGTH_LONG).show();
}
@Override
protected void onPreExecute() {}
}
这是我的代码,在运行文件时显示内部服务器error.i给了toast消息来检查它是否需要所有细节,但它显示内部服务器错误并且我在清单中也给了用户权限
03-10 11:53:55.055 6520-6524 /? E / dalvikvm:heapsize setIdealFootprint开销6733824 03-10 11:53:56.116 7795-7795 / com.myapps.materialapplication E / dalvikvm:heapsize setIdealFootprint max1 9109504 03-10 11:53:56.116 7795-7795 / com.myapps.materialapplication E / dalvikvm:heapsize setIdealFootprint max2 9109504 03-10 11:53:56.116 7795-7795 / com.myapps.materialapplication E / dalvikvm:heapsize setIdealFootprint overhead 6733824 03-10 11:53:56.176 7795-7795 / com.myapps.materialapplication E / dalvikvm:heapsize setIdealFootprint max1 9648128 03-10 11:53:56.176 7795-7795 / com.myapps.materialapplication E / dalvikvm:heapsize setIdealFootprint max2 9648128 03-10 11:53:56.176 7795-7795 / com.myapps.materialapplication E / dalvikvm:heapsize setIdealFootprint overhead 6733824 03-10 11:53:56.236 7795-7795 / com.myapps.materialapplication E / dalvikvm:heapsize setIdealFootprint max1 10200064 03-10 11:53:56.236 7795-7795 / com.myapps.materialapplication E / dalvikvm:heapsize setIdealFootprint max2 10200064 03-10 11:53:56.236 7795-7795 / com.myapps.materialapplication E / dalvikvm:heapsize setIdealFootprint overhead 6733824 03-10 11:54:21.771 687-689 /? E / dalvikvm:heapsize setIdealFootprint overhead 6733824
这是我的logcat错误
答案 0 :(得分:0)
内部服务器错误不是客户端,但它来自服务器,当您从服务器端获得请求代码500时,您将收到内部服务器错误消息。你能否在日志中打印你的回复代码,检查应该是500.请检查你的服务器端,因为你可能会错过一些参数或者某些参数值可能为空。
希望这会告诉你。