2016-07-27 3 views
0

등록 된 고객을 등록하려고했지만 오류 응답이 나타납니다. 성공 및 실패 사례 모두에서 오류 응답 만 받고 내 기록에는 "BasicNetwork.performRequest : 예기치 않은 응답 코드 400"이라는 오류가 있습니다.예기치 않은 코드 400 발리볼 오류

여기

import android.os.Bundle; 
import android.support.design.widget.FloatingActionButton; 
import android.text.Editable; 
import android.text.TextWatcher; 
import android.view.View; 
import android.widget.ArrayAdapter; 
import android.widget.AutoCompleteTextView; 
import android.widget.EditText; 
import android.widget.Toast; 

import com.android.volley.AuthFailureError; 
import com.android.volley.NetworkResponse; 
import com.android.volley.Request; 
import com.android.volley.RequestQueue; 
import com.android.volley.Response; 
import com.android.volley.VolleyError; 
import com.android.volley.toolbox.JsonArrayRequest; 
import com.android.volley.toolbox.StringRequest; 
import com.android.volley.toolbox.Volley; 

import org.json.JSONArray; 
import org.json.JSONException; 
import org.json.JSONObject; 

import java.util.ArrayList; 
import java.util.HashMap; 
import java.util.Map; 
public class CustomerRegistration extends BaseActivity implements View.OnClickListener { 
     FloatingActionButton registrationbtn; 
     EditText firstname,lastname,loginid,confirmlogin,mobile,city,password,confirmpassword; 
     AutoCompleteTextView country; 
     String URL_Register="http://188.166.237.82/api/customer"; 
     String URL_Country="http://188.166.237.82/api/country"; 
     ArrayList<String>arrayList; 
     RequestQueue requestQueue; 
     ArrayAdapter<String>arrayAdapter; 
     String firstName,lastName,loginId,confirmLoginId,Mobile,City,Password,confirmPassword,Country; 
     String namepattern="^[a-zA-Z\\s]*$"; 
     String emailpattern="[a-zA-Z0-9._-][email protected][a-z]+\\.+[a-z]+"; 
     String mobilepattern="[0-9]{10}$"; 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_customer_registration); 
     registrationbtn= (FloatingActionButton) findViewById(R.id.cust_btn_registeration); 
     country= (AutoCompleteTextView) findViewById(R.id.cust_act_country); 
     firstname= (EditText) findViewById(R.id.cust_et_firstname); 
     lastname= (EditText) findViewById(R.id.cust_et_lastname); 
     loginid= (EditText) findViewById(R.id.cust_et_loginid); 
     confirmlogin= (EditText) findViewById(R.id.cust_et_confirm_loginid); 
     mobile= (EditText) findViewById(R.id.cust_et_mobile); 
     city= (EditText) findViewById(R.id.cust_et_city); 
     password= (EditText) findViewById(R.id.cust_et_password); 
     confirmpassword= (EditText) findViewById(R.id.cust_et_confirm_password); 
     arrayList=new ArrayList<String>(); 
     clientSideValidations(); 
     registrationbtn.setOnClickListener(this); 
     country.setOnClickListener(this); 
     getCountryList(); 
    } 
    private void getCountryList(){ 
     JsonArrayRequest jsonArrayRequest=new JsonArrayRequest(URL_Country, new Response.Listener<JSONArray>() { 
      @Override 
      public void onResponse(JSONArray response) { 
       for (int i=0;i<response.length();i++){ 
        try { 
         JSONObject jsonObject=response.getJSONObject(i); 
         String countryname=jsonObject.getString("name"); 
         arrayList.add(countryname); 
         arrayAdapter=new ArrayAdapter<String>(CustomerRegistration.this,android.R.layout.simple_spinner_item,arrayList); 
         arrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); 
         country.setAdapter(arrayAdapter); 
        } catch (JSONException e) { 
         e.printStackTrace(); 
        } 

       } 
      } 
     }, new Response.ErrorListener() { 
      @Override 
      public void onErrorResponse(VolleyError error) { 

      } 
     }); 
     requestQueue=Volley.newRequestQueue(this); 
     requestQueue.add(jsonArrayRequest); 
    } 

    @Override 
     public void onClick(View v) { 
     firstName=firstname.getText().toString().trim(); 
     lastName=lastname.getText().toString().trim(); 
     loginId=loginid.getText().toString().trim(); 
     confirmPassword=confirmpassword.getText().toString().trim(); 
     confirmLoginId=confirmlogin.getText().toString().trim(); 
     Password=password.getText().toString().trim(); 
     Mobile=mobile.getText().toString().trim(); 
     City=city.getText().toString().trim(); 
     Country=country.getText().toString().trim(); 
     if(firstName.isEmpty()||lastName.isEmpty()||loginId.isEmpty()||confirmLoginId.isEmpty()||Mobile.isEmpty()||City.isEmpty() 
     ||Password.isEmpty()||confirmPassword.isEmpty()||Country.isEmpty()){ 
      Toast.makeText(CustomerRegistration.this, "Some Fields Are Empty", Toast.LENGTH_SHORT).show(); 
     }else { 

      sendFields(); 
     } 
    } 
    private void sendFields(){ 
     progressDialog.setMessage("Loading......"); 
     progressDialog.show(); 
     StringRequest stringRequest=new StringRequest(Request.Method.POST, URL_Register, new Response.Listener<String>() { 
      @Override 
      public void onResponse(String response) { 
       progressDialog.hide(); 
       try { 
        JSONObject jsonObject1=new JSONObject(response); 
        String result=jsonObject1.getString("message"); 
        Toast.makeText(CustomerRegistration.this, result, Toast.LENGTH_SHORT).show(); 
//     AlertDialog.Builder builder=new AlertDialog.Builder(CustomerRegistration.this).setTitle("Congratulations.....!"+result) 
//       .setMessage("Successfully Registered..! Activation Link Send to your Registered Mail Id ").setNeutralButton("OK", new DialogInterface.OnClickListener() { 
//        @Override 
//        public void onClick(DialogInterface dialog, int which) { 
//         startActivity(new Intent(CustomerRegistration.this,LoginActivity.class)); 
//        } 
//       }); 
//     Dialog dialog=builder.create(); 
//     dialog.setCanceledOnTouchOutside(false); 
//     dialog.show(); 
       } catch (JSONException e) { 
        e.printStackTrace(); 
       } 
      } 

     }, new Response.ErrorListener() { 
      @Override 
      public void onErrorResponse(VolleyError error) { 
       progressDialog.hide(); 
       NetworkResponse networkResponseVolley = error.networkResponse; 
       String error_message = new String(networkResponseVolley.data); 
       try { 
        JSONObject jsonObject = new JSONObject(error_message); 
//     String bookingError=jsonObject.getString("message"); 
//     Toast.makeText(CustomerRegistration.this, bookingError, Toast.LENGTH_SHORT).show(); 
        JSONArray jsonArray = jsonObject.getJSONArray("errors"); 
        for (int i = 0; i < jsonArray.length(); i++) { 
         String errorResponse = jsonArray.getString(i); 
         Toast.makeText(CustomerRegistration.this, errorResponse.toString(), Toast.LENGTH_SHORT).show(); 
        } 
       } catch (JSONException e) { 
        e.printStackTrace(); 
       } 
      } 

     }) 
     { 
      @Override 
      protected Map<String, String> getParams() throws AuthFailureError { 
       HashMap<String,String> params=new HashMap<String, String>(); 
       params.put("company","GeoAppstractSolutions"); 
       params.put("firstname",firstname.getText().toString().trim()); 
       params.put("lastname",lastname.getText().toString().trim()); 
       params.put("phone",mobile.getText().toString().trim()); 
       params.put("loginid",loginid.getText().toString().trim()); 
       params.put("city",city.getText().toString().trim()); 
       params.put("country",country.getText().toString().trim()); 
       params.put("password",password.getText().toString().trim()); 
       params.put("password_confirmation",confirmpassword.getText().toString().trim()); 
//    params.put("Content-Type", "application/json"); 
       return params; 

      } 
     }; 
     requestQueue= Volley.newRequestQueue(this); 
     requestQueue.add(stringRequest); 

    } 
    private void clientSideValidations(){ 
     firstname.addTextChangedListener(new TextWatcher() { 
      @Override 
      public void beforeTextChanged(CharSequence s, int start, int count, int after) { 

      } 

      @Override 
      public void onTextChanged(CharSequence s, int start, int before, int count) { 

      } 

      @Override 
      public void afterTextChanged(Editable s) { 
       firstName=firstname.getText().toString().trim(); 
       if(!firstName.matches(namepattern)){ 
        firstname.setError("Use Alphabects only"); 
       }else{ 
        firstname.setError(null); 
       } 
      } 
     }); 
     lastname.addTextChangedListener(new TextWatcher() { 
      @Override 
      public void beforeTextChanged(CharSequence s, int start, int count, int after) { 

      } 

      @Override 
      public void onTextChanged(CharSequence s, int start, int before, int count) { 

      } 

      @Override 
      public void afterTextChanged(Editable s) { 
       lastName=lastname.getText().toString().trim(); 
       if(!lastName.matches(namepattern)){ 
        lastname.setError("Use Alphabects only"); 
       }else{ 
        lastname.setError(null); 
       } 
      } 
     }); 
     mobile.addTextChangedListener(new TextWatcher() { 
      @Override 
      public void beforeTextChanged(CharSequence s, int start, int count, int after) { 

      } 

      @Override 
      public void onTextChanged(CharSequence s, int start, int before, int count) { 

      } 

      @Override 
      public void afterTextChanged(Editable s) { 
       Mobile=mobile.getText().toString().trim(); 
       if(!Mobile.matches(mobilepattern)){ 
        mobile.setError("Mobile Number length should be 10"); 
       }else{ 
        mobile.setError(null); 
       } 
      } 
     }); 
     loginid.addTextChangedListener(new TextWatcher() { 
      @Override 
      public void beforeTextChanged(CharSequence s, int start, int count, int after) { 

      } 

      @Override 
      public void onTextChanged(CharSequence s, int start, int before, int count) { 

      } 

      @Override 
      public void afterTextChanged(Editable s) { 
       loginId=loginid.getText().toString().trim(); 

       if(!loginId.matches(emailpattern)){ 
        loginid.setError("Invalid E-mail Format"); 
       }else{ 
        loginid.setError(null); 
       } 
      } 
     }); 
     confirmlogin.addTextChangedListener(new TextWatcher() { 
      @Override 
      public void beforeTextChanged(CharSequence s, int start, int count, int after) { 

      } 

      @Override 
      public void onTextChanged(CharSequence s, int start, int before, int count) { 

      } 

      @Override 
      public void afterTextChanged(Editable s) { 

       confirmLoginId=confirmlogin.getText().toString().trim(); 

       if(!confirmLoginId.equals(loginId)){ 
        confirmlogin.setError("Both Login and ConfirmLogin should be match"); 
       }else{ 
        confirmlogin.setError(null); 
       } 
      } 
     }); 

     city.addTextChangedListener(new TextWatcher() { 
      @Override 
      public void beforeTextChanged(CharSequence s, int start, int count, int after) { 

      } 

      @Override 
      public void onTextChanged(CharSequence s, int start, int before, int count) { 

      } 

      @Override 
      public void afterTextChanged(Editable s) { 

       City=city.getText().toString().trim(); 
       if(!City.matches(namepattern)){ 
        city.setError("Use Alphabects only"); 
       }else{ 
        city.setError(null); 
       } 
      } 
     }); 
     country.addTextChangedListener(new TextWatcher() { 
      @Override 
      public void beforeTextChanged(CharSequence s, int start, int count, int after) { 

      } 

      @Override 
      public void onTextChanged(CharSequence s, int start, int before, int count) { 

      } 

      @Override 
      public void afterTextChanged(Editable s) { 
       Country=country.getText().toString().trim(); 
       if(!Country.matches(namepattern)){ 
        country.setError("Use Alphabects only"); 
       }else{ 
        country.setError(null); 
       } 
      } 
     }); 
     password.addTextChangedListener(new TextWatcher() { 
      @Override 
      public void beforeTextChanged(CharSequence s, int start, int count, int after) { 

      } 

      @Override 
      public void onTextChanged(CharSequence s, int start, int before, int count) { 

      } 

      @Override 
      public void afterTextChanged(Editable s) { 
       Password=password.getText().toString().trim(); 

       if (Password.length()<6){ 
        password.setError("Password should be more than 6 characters"); 
       }else{ 
        password.setError(null); 
       } 
      } 
     }); 
     confirmpassword.addTextChangedListener(new TextWatcher() { 
      @Override 
      public void beforeTextChanged(CharSequence s, int start, int count, int after) { 

      } 

      @Override 
      public void onTextChanged(CharSequence s, int start, int before, int count) { 

      } 

      @Override 
      public void afterTextChanged(Editable s) { 
       confirmPassword=confirmpassword.getText().toString().trim(); 
       if (!confirmPassword.equals(Password)){ 
        confirmpassword.setError("Both Possword and ConfirmPassword should be match"); 
       }else{ 
        confirmpassword.setError(null); 
       } 
      } 
     }); 
    } 


} 
+0

[Android Volley - BasicNetwork.performRequest : 예기치 않은 응답 코드 400] (http://stackoverflow.com/questions/26796965/android-volley-basicnetwork-performrequest-unexpected-response-code-400) 중복 가능성 – Danieboy

+0

오류 코드 (400)는 잘못된 요청 일 수있다. 서버에서 예상되는 올바른 매개 변수/올바른 헤더를 보내고 있는지 확인하십시오. – SripadRaj

+0

이전에 그 문제는 내가이 문제에 직면하고있다. –

답변

0

는 우체부에서 동일한 매개 변수를 사용하여 웹 서비스 테스트를 시도하고 상태 코드를 확인 내 코드입니다. 그것이 같으면 올바른 매개 변수를 전송하지 않습니다.