Home > Software engineering >  Spring boot Api working fine in postman for hindi text but while sending request from mobile apps hi
Spring boot Api working fine in postman for hindi text but while sending request from mobile apps hi

Time:10-16

Spring boot Api working fine in postman for hindi text but while sending request from mobile apps hindi data not receiving properly { "healthSubcenterName": "00&\u0015\u0015", "phcName": "8&&\u0015",

}

CodePudding user response:

I think due to problem from android side

CodePudding user response:

public void saveDataToServer (String key){

    long unixTime = System.currentTimeMillis() / 1000L;

    Thread thread = new Thread(new Runnable() {
        @Override
        public void run() {

            JSONArray jsonArray = new JSONArray();

            try {
                APICallD2D apicalld2d = new APICallD2D();
                URL url = new URL(apicalld2d.d2dURL   "hbncRegister");
                HttpURLConnection conn = (HttpURLConnection) url.openConnection();
                conn.setRequestMethod("POST");
                conn.setRequestProperty("Content-Type", "application/json;charset=UTF-8");
                conn.setRequestProperty("Accept","application/json");
                conn.setRequestProperty("token",key);
                conn.setDoOutput(true);
                conn.setDoInput(true);

                JSONObject jsonObject = new JSONObject();
                jsonObject.put("ashaName", mEtAshaName.getText().toString());
                jsonObject.put("babyEyeCondition", intBabyEyeCondition);
                jsonObject.put("babyFedAfterBirth", intBabyFedBirth);
                jsonObject.put("babyFirstBreastfed", mEtBabyFirstBreastfed.getText().toString());
                jsonObject.put("babyGender", intBabyGender);
                jsonObject.put("beneficiaryid", benficieryID);
                jsonObject.put("bodyIsSluggish", intBabyIsSluggish);
                jsonObject.put("childStatus", intChildStatus);
                jsonObject.put("chileImmunizationStatus", intChildVaccine);
                jsonObject.put("createdBy", userName);
                jsonObject.put("createdDate", unixTime);
                jsonObject.put("cryingSlow", intCryingSlow);
                jsonObject.put("dateCompletionPregnancy", mEtDatePregnancy.getText().toString());
                jsonObject.put("dateOfDelivery", mEtDod.getText().toString());
                jsonObject.put("dateTimeOfFirstTraining", mEtDateAndTimeFirstTraining.getText().toString());
                jsonObject.put("deliveryTime", mEtDeliveryTime.getText().toString());
                jsonObject.put("dischargeDateFromHospital", mEtDischargeDate.getText().toString());
                jsonObject.put("fatherName", mEtFatherName.getText().toString());
                jsonObject.put("motherName", mEtMotherName.getText().toString());
                jsonObject.put("healthSubcenterName", mEtHealthCenter.getText().toString());
                jsonObject.put("homeVisitDate", intHomeVisitDate);
                jsonObject.put("houseoldId", HouseholdID);
                jsonObject.put("howBabyBreastfeed", intHowBabyBreastFed);
                jsonObject.put("howManyWeekHaveBeenBorn", mEtHowManyWeeks.getText().toString());
                jsonObject.put("isMotherHavingTroubleBreastfeeding", mEtTroubleBreastFedding.getText().toString());
                jsonObject.put("isThereBleedingFromUmbilicalCord", intBleedCord);
                jsonObject.put("lessMilkIsDrinking", intLessMilkDrinking);
                jsonObject.put("loginId", hbnccount);

// jsonObject.put("logonCoordinates", et_remarks.getText().toString()); jsonObject.put("motherName", mEtMotherName.getText().toString()); jsonObject.put("motherStatus", intMotherStatus); jsonObject.put("newbornWeightRecorded", intChildRecordedWeight); jsonObject.put("notCrying", intNotCrying); jsonObject.put("notDrinkingMilk", intNotDrinkingMilk); jsonObject.put("phcName", mEtPHCName.getText().toString()); jsonObject.put("placeOfDelivery", intPlaceOfDelivery); jsonObject.put("problemInBreastfeeding", mEtProblemBreastFeeding.getText().toString()); jsonObject.put("recordBabyTemp", mEtRecordBabyTemp.getText().toString()); jsonObject.put("registrationOfBirth", intBirthRegistration); jsonObject.put("typeOfDelivery", intTypeOfDelivery); jsonObject.put("updatedBy", userName); jsonObject.put("updatedDate", unixTime); jsonObject.put("village_name", mEtVillageName.getText().toString()); jsonObject.put("villageid", BaseActivity.villageid); jsonObject.put("vistDay", mEtVisitDay.getText().toString()); jsonObject.put("weighingMachineScaleColor", intWeighingMachineColor); jsonObject.put("weightAtBirth", mEtWeight.getText().toString()); jsonObject.put("weightInKg", mEtWeightInKg.getText().toString());

                jsonObject.put("whetherTheNewbornWasBeingLooked", sphbnc6yes_val);
                jsonObject.put("childWasWipedWithCleanCloth", sphbnc6_1yes_val);
                jsonObject.put("childKeptWarm", sphbnc6_2yes_val);
                jsonObject.put("childWasGivenAbath", sphbnc6_3yes_val);
                jsonObject.put("childIsWrappedInClothAndKeptTotheMother", sphbnc6_4yes_val);
                jsonObject.put("startedBreastFeedingOnly", sphbnc6_5yes_val);
                jsonObject.put("wasThereAnythinUnsualWithTheBath", sphbnc7yes_val);

                jsonObject.put("howManyTimesTheMotherFeedsHerStomachIn24hours", et_sec_a_ques1.getText().toString());
                jsonObject.put("howManyPadsHaveBeenChangedInDayForbleeding", sp_sec_a_ques4.getSelectedItemPosition());
                jsonObject.put("duringTheWinterSeasonIsKeptWarm", sp_sec_a_ques3.getSelectedItemPosition());
                jsonObject.put("isTheChildBreastFedProperly", sp_sec_a_ques4.getSelectedItemPosition());
                jsonObject.put("doesTheChildCryContinouslyOrUrniateLessThan6TimesDay", sp_sec_a_ques5.getSelectedItemPosition());

                jsonObject.put("measureAndCheckTheTemperature", et_sec_b_ques1.getText().toString());
                jsonObject.put("motherMilkIsNotBeingProducedAfterDelivery", sp_sec_b_ques4.getSelectedItemPosition());
                jsonObject.put("doesTheMotherGrumbleUnevnlyOrHaveSeizure", sp_sec_b_ques3.getSelectedItemPosition());
                jsonObject.put("doesTheMotherHaveCrackedNipplePainBreast", sp_sec_b_ques5.getSelectedItemPosition());
                jsonObject.put("wateryDischargeWithFoulSmell", sp_sec_b_ques2.getSelectedItemPosition());

                jsonObject.put("areEyesSwollen", sp_sec_c_qus1.getSelectedItemPosition());
                jsonObject.put("Weight", et_sec_c_qus2.getText().toString());
                jsonObject.put("measureAndEnterTemperature", et_sec_c_qus3.getText().toString());
                jsonObject.put("pusFilledPimplesInSkin", sp_sec_c_qus4.getSelectedItemPosition());
                jsonObject.put("crackedRednessOfTwistedSkin", et_sec_c_qus5.getText().toString());
                jsonObject.put("seizures", et_sec_c_qus6.getText().toString());
                jsonObject.put("isBreathGoingFast", et_sec_c_qus7.getText().toString());
                jsonObject.put("isChildReferedPHCRHSDH", et_sec_c_qus8.getText().toString());

                jsonObject.put("allOrgansAreLetharic", et_hbnc_sec_d_question1.getText().toString());
                jsonObject.put("isDrinkingLessMilk", et_hbnc_sec_d_question2.getText().toString());
                jsonObject.put("hasStoppedDrinkginMilk", et_hbnc_sec_d_question3.getText());
                jsonObject.put("slowCrying", et_hbnc_sec_d_question4.getText().toString());
                jsonObject.put("stopCyring", et_hbnc_sec_d_question4.getText().toString());
                jsonObject.put("bloatedStomachOrMotherTellsThatChildsVomitsAgain", et_hbnc_sec_d_question5.getText().toString());
                jsonObject.put("pusIntheNavel", et_hbnc_sec_d_question6.getText().toString());


                jsonObject.put("doesMotherHaveProblem", intDoesMotherProblem);
                jsonObject.put("id", hbnccount);
                jsonObject.put("initiationBreastFeedingstart", intStartBreastFeeding);


               /* jsonObject.put("weightInKgSupervisor", intWeightInKgSuper);
                jsonObject.put("whenWasTheBabyFirstBreastfedSupervisor", intWhenWasBabyFirstBreastfedSuper);
                jsonObject.put("babyEyeConditionSupervisor", intBabyEyeConditionSuperSuper);
                jsonObject.put("dateAndTimeOfFirstTrainingSupervisor", intDateTimeFirstTrainingSuper);
                jsonObject.put("dateOfCompletionPregnancySupervisor", intDateOfCompletionSuper);
                jsonObject.put("deliveryTimeSupervisor", intDeliveryTimeSuper);
                jsonObject.put("doesMotherHaveAnyProblemSupervisor", intDoesMotherHaveAnyProblemSuper);
                jsonObject.put("enterChildPhysicalConditionSupervisor", intEnterTheChildPhyscalSuper);
                jsonObject.put("howDidTheBabyBreastfedSupervisor", intHowDidTheBreastfeedSuper);
                jsonObject.put("howManyWeeksHaveBeenBornSupervisor", intHoeManyWeeksHaveBeenBornSuper);
                jsonObject.put("ifThereIsAnyProblemInBreastfeedingSupervisor", intIfThereIsAnyProblemInBreastfeedingSuper);
                jsonObject.put("isTheMotherHavingTroubleBreastfeedingSupervisor", intIsTheMotherHavingTroubleBreastfeedingSuper);
                jsonObject.put("isThereBleedingUmbilicalCordSupervisor", intIsthereBleedingSuper);
                jsonObject.put("measureAndRecordBabyTempSupervisor", intMeasureAndRecordBabysBodyTempSuper);
                jsonObject.put("weighingMachineScaleSupervisor", intWeighingMacineSuper);

                jsonObject.put("whetherTheNewbornWasBeingLookedSupervisor", sphbnc6.getSelectedItemPosition());
                jsonObject.put("childWasWipedWithCleanClothSupervisor", spHbnc6_1.getSelectedItemPosition());
                jsonObject.put("childKeptWarmSupervisor", spHbnc6_2.getSelectedItemPosition());
                jsonObject.put("childWasGivenAbathSupervisor", spHbnc6_3.getSelectedItemPosition());
                jsonObject.put("childIsWrappedInClothAndKeptTotheMotherSupervisor", spHbnc6_4.getSelectedItemPosition());
                jsonObject.put("startedBreastFeedingOnlySupervisor", spHbnc6_5.getSelectedItemPosition());
                jsonObject.put("wasThereAnythinUnsualWithTheBathSupervisor", spHbnc7.getSelectedItemPosition());*/

                jsonObject.put("supervisorTickMarks", sup_comment_selected);
                jsonObject.put("supervisorRemarks", et_hbnc_sup_remarks.getText().toString());
                jsonObject.put("signaturesWithDateOfSupervision", et_hbnc_sup_date.getText().toString());

                jsonArray.put(jsonObject);
                String jsonText = jsonArray.toString();

                Log.v("http", jsonText);
                DataOutputStream os = new DataOutputStream(conn.getOutputStream());
                //os.writeBytes(URLEncoder.encode(jsonParam.toString(), "UTF-8"));
                os.writeBytes(jsonText);

                os.flush();
                os.close();

                BufferedReader br = null;
                if (100 <= conn.getResponseCode() && conn.getResponseCode() <= 399) {
                    br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
                } else {
                    br = new BufferedReader(new InputStreamReader(conn.getErrorStream()));
                }

                StringBuilder total = new StringBuilder();
                for (String line; (line = br.readLine()) != null; ) {
                    total.append(line).append('\n');
                }

                Log.v("http", String.valueOf(conn.getResponseCode()));
                Log.v("http" , total.toString());


                conn.disconnect();
            } catch (Exception e) {
                Log.v("http" , e.getMessage());
                e.printStackTrace();
            }
        }
    });

    thread.start();
}
  • Related