When adding String I get null in MediaType OkHttp3

  android, java, okhttp

Why am I getting null? Why is the phone number transmitted, but not the usual string?
I’ve been working on this problem all day, please help.

firstName_str = firstName.getText().toString();
ip_str = ip;
lastName_str = lastName.getText().toString();
email_str = email.getText().toString();
getPhoneNumber_str = firebaseAuth.getCurrentUser().getPhoneNumber();
getPhoneNumber_str = getPhoneNumber_str.replace("+", "");
Log.d("ccp_str2", "firstName_str: " + firstName_str);
Log.d("ccp_str2", "ip_str: " + ip_str);
Log.d("ccp_str2", "lastName_str: " + lastName_str);
Log.d("ccp_str2", "email_str: " + email_str);
Log.d("ccp_str2", "getPhoneNumber_str: " + getPhoneNumber_str);

MediaType JSON = MediaType.parse("application/json; charset=utf-8");
String json = "{n    "ai": "222222",n    "ci": "111",n    "gi": "111",n    "userip": "+ip_str+",n    "firstname": "+firstName_str+",n    "lastname": "+lastName_str+",n    "email": "+email_str+",n    "password": "Aa12345!",n    "phone": "+getPhoneNumber_str+",n "so":"start"n}";

RequestBody body = RequestBody.create(JSON, json);

OkHttpClient client = new OkHttpClient().newBuilder()
        .build();
Request request = new Request.Builder()
        .url("https://platform.link.com/api/signup/procform")
        .method("POST", body)
        .addHeader("x-trackbox-username", "name")
        .addHeader("x-trackbox-password", "pass")
        .addHeader("x-api-key", "key")
        .addHeader("Content-Type", "application/json")
        .build();
Response response = client.newCall(request).execute();
String str_leads = response.body().string();
Log.d("str_leads", "str_leads: " + str_leads);

Log ccp_str2:

ccp_str2: firstName_str: TestName
ccp_str2: ip_str: 111.111.111.111
ccp_str2: lastName_str: TestLast
ccp_str2: email_str: [email protected]
ccp_str2: getPhoneNumber_str: 441234567890

Log str_leads:

str_leads: {"status":false,"data":"IP is not valid","addonData":{"ai":"222222","ci":"111","gi":"111","userip":null,"firstname":null,"lastname":null,"email":null,"password":"Aa12345!","phone":441234567890,"so":"start"}}

Source: Android Questions

LEAVE A COMMENT