Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/207.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在使用改装提交数据时收到错误的请求_Java_Android_Api_Retrofit_Bad Request - Fatal编程技术网

Java 在使用改装提交数据时收到错误的请求

Java 在使用改装提交数据时收到错误的请求,java,android,api,retrofit,bad-request,Java,Android,Api,Retrofit,Bad Request,当我将数据发布到我的服务器上时,我得到错误代码400,请求错误,但情况是数据被发布,但我的响应。body()获取空数据并显示错误请求的消息。 我正在发布注册类和界面 Signup.java OkHttpClient httpClient = new OkHttpClient(); httpClient.networkInterceptors().add(new Interceptor() { @Override publ

当我将数据发布到我的服务器上时,我得到错误代码400,请求错误,但情况是数据被发布,但我的响应。body()获取空数据并显示错误请求的消息。 我正在发布注册类和界面

Signup.java

      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();

                            }

                        });
                    }
                }
            }
        });
OkHttpClient-httpClient=new-OkHttpClient();
httpClient.networkInterceptors().add(新的拦截器(){
@凌驾
public com.squareup.okhttp.Response intercept(Chain-Chain)抛出IOException{
com.squareup.okhttp.Request Request=chain.Request().newBuilder()
.addHeader(“X-Parse-Application-Id”,“D3E7oCNNNI0dkv9GYmqZGw0h0GVnbCmJ65JLj7di”)
.addHeader(“X-Parse-REST-API-Key”,“HO89YU3OETGNL8XLNV6Y8OV8TV6JW52SORXNKXL”)
.addHeader(“内容类型”、“应用程序/json”)
.build();
返回链。继续(请求);
}
});
改装=新改装.Builder()
.baseUrl(“https://api.parse.com")
.addConverterFactory(GsonConverterFactory.create())
.client(httpClient)
.build();
signup.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
{
if(e5.getText().toString().length()<8&&e5.getText().toString().length()!=0)
{
Toast.makeText(getApplicationContext(),“密码至少应为8个字符”,Toast.LENGTH_LONG).show();
}
}
{
如果(e1.getText().toString().length()==0||
e2.getText().toString().length()=0||
e4.getText().toString().length()=0||
e5.getText().toString().length()=0){
Toast.makeText(getApplicationContext(),“某些字段为空”,Toast.LENGTH_LONG.show();
}否则{
progress=ProgressDialog.show(signup.this,“signup”,
“请稍等”,对);
字符串s1=e1.getText().toString();
字符串s2=e2.getText().toString();
int countrycode=新整数(OTP_Activity.t).intValue();
Long phonenumber=new Long(Long.parseLong(OTP_Activity.phnnum));
最终字符串s3=s1.concat(s2);
signupapi thisapi=reformation.create(signupapi.class);
HashMap params=新的HashMap();
参数put(“用户名”,OTP_活动电话);
参数put(“全名”,s3);
参数put(“password”,e5.getText().toString());
put(“email”,e4.getText().toString());
参数put(“名字”,s1);
参数put(“姓氏”,s2);
参数put(“国家代码”,国家代码);
参数put(“电话号码”,电话号码);
Call Call=thisapi.postData(params);
Log.d(“全名”,s3);
Log.d(“电话”,OTP_活动电话);
Log.d(“e5”,e5.getText().toString());
Log.d(“e4”,e4.getText().toString());
日志d(“名字”,s1);
Log.d(“姓氏”,s2);
Log.d(“countryCode”,String.valueOf(countryCode));
Log.d(“PHoneNumber”,String.valueOf(PHoneNumber));
//现在我们有字符串形式的信息。让我们在编辑器的帮助下存储它们
call.enqueue(新回调(){
@凌驾
公共响应(响应、改装){
if(response.body()!=null){
进步。解散();
意向意向=新意向(signup.this,Bottom\u Tabs\u Activity.class);
星触觉(意向);
}否则{
Toast.makeText(getApplicationContext(),response.message(),Toast.LENGTH\u SHORT.show();
}
}
@凌驾
失效时的公共无效(可丢弃的t){
进步。解散();
//Toast.makeText(getApplicationContext(),“”,Toast.LENGTH_SHORT.show();
}
});
}
}
}
});
注册接口

package com.example.vikrant.safeshelter.Login;

import java.util.HashMap;

import retrofit.Call;
import retrofit.http.Body;
import retrofit.http.POST;






public interface signupapi
{

    @POST("/1/classes/_User")
    Call<Signupmodel> postData(@Body HashMap hm);
}
package com.example.vikrant.safehorder.Login;
导入java.util.HashMap;
进口改装。电话;
导入reformation.http.Body;
导入reformation.http.POST;
公共接口注册API
{
@POST(“/1/classes/\u User”)
调用postData(@Body HashMap hm);
}

尝试了
String
而不是
HashMap
?然后在
RestController
方法中将
String
对象更改为
json
。不,我没有,因为这必须通过使用hashmap完成,使用hashmap处理所有post请求,并使用字符串获取请求@VikrantKashyapI刚刚建议您尝试并调试代码,以跟踪您的数据是否收到?并在评论中作出相应回应。请在将
hashmap
替换为
String
后,将您的
StackTrace
添加到@vikrantkashyapa,您仍然收到错误吗@vikrantSinghtried
String
而不是
HashMap
?然后更改您的
字符串