当我将数据发布到我的服务器上时,我收到错误代码400,错误请求,但情况是数据已发布但我的response.body()正在获取空数据并显示消息一个糟糕的请求。 我发布了注册类和界面。
Signup.java
int arryNumbers[][]= new int[4][5];
Signup_Interface
OkHttpClient httpClient = new OkHttpClient();
httpClient.networkInterceptors().add(new Interceptor() {
@Override
public com.squareup.okhttp.Response intercept(Chain chain) throws IOException {
com.squareup.okhttp.Request request = chain.request().newBuilder()
.addHeader("X-Parse-Application-Id", "D3E7oCNNNI0dkv9GYmqZGw0h0GVnbCmJ65JLj7di")
.addHeader("X-Parse-REST-API-Key", "hO89YU3OETgnL8Xlnvb6y8ov8Tv6jw52SORxNkxl")
.addHeader("Content-Type", "application/json")
.build();
return chain.proceed(request);
}
});
retrofit = new Retrofit.Builder()
.baseUrl("https://api.parse.com")
.addConverterFactory(GsonConverterFactory.create())
.client(httpClient)
.build();
signup.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
{
if (e5.getText().toString().length() < 8 && e5.getText().toString().length()!=0 )
{
Toast.makeText(getApplicationContext(), "password should be of minimum 8 characters", Toast.LENGTH_LONG).show();
}
}
{
if (e1.getText().toString().length() == 0 ||
e2.getText().toString().length() == 0 ||
e4.getText().toString().length() == 0 ||
e5.getText().toString().length() == 0) {
Toast.makeText(getApplicationContext(), "Some fields are left empty", Toast.LENGTH_LONG).show();
} else {
progress = ProgressDialog.show(signup.this, "Signing up",
"Please wait", true);
String s1 = e1.getText().toString();
String s2 = e2.getText().toString();
int countrycode=new Integer(OTP_Activity.t).intValue();
Long phonenumber=new Long(Long.parseLong(OTP_Activity.phnnum));
final String s3 = s1.concat(s2);
signupapi thisapi = retrofit.create(signupapi.class);
HashMap params = new HashMap();
params.put("username", OTP_Activity.phone);
params.put("fullName", s3);
params.put("password", e5.getText().toString());
params.put("email", e4.getText().toString());
params.put("firstName", s1);
params.put("lastName", s2);
params.put("countryCode", countrycode);
params.put("phoneNumber", phonenumber);
Call<Signupmodel> call = thisapi.postData(params);
Log.d("full name", s3);
Log.d("phone", OTP_Activity.phone);
Log.d("e5", e5.getText().toString());
Log.d("e4", e4.getText().toString());
Log.d("firstName",s1);
Log.d("lastName", s2);
Log.d("countryCode", String.valueOf(countrycode));
Log.d("PHoneNumber", String.valueOf(phonenumber));
// as now we have information in string. Lets stored them with the help of editor
call.enqueue(new Callback<Signupmodel>() {
@Override
public void onResponse(Response<Signupmodel> response, Retrofit retrofit) {
if (response.body() != null) {
progress.dismiss();
Intent intent = new Intent(signup.this, Bottom_Tabs_Activity.class);
startActivity(intent);
} else {
Toast.makeText(getApplicationContext(), response.message(), Toast.LENGTH_SHORT).show();
}
}
@Override
public void onFailure(Throwable t) {
progress.dismiss();
// Toast.makeText(getApplicationContext(),"",Toast.LENGTH_SHORT).show();
}
});
}
}
}
});