java - Android 中 makeHttpRequest 调用中的 json 为 null

标签 java android json

我有一个名为 ConnectionToOracle 的 java web 项目。我有一个名为 Sign_Up_Servlet 的 servlet。

所以我有以下代码:

 private static String url_sign_up_execute
                = "http://10.11.201.84:8084//ConnectionToOracle/Sign_Up_Servlet"; 

private class GetSignUpStatus extends AsyncTask<String, Integer, String> {


        ProgressDialog pDialog = new ProgressDialog(Sign_Up.this);

        @Override
        protected void onPreExecute() {
            // TODO Auto-generated method stub
            super.onPreExecute();
            pDialog.setMessage("Please wait...");
            pDialog.show(); 
        }

        @Override
        protected void onPostExecute(String result) {
            // TODO Auto-generated method stub
            super.onPostExecute(result);


            pDialog.dismiss();

            if (json == null) {
                pDialog.dismiss();
                Toast.makeText(
                        getApplicationContext(),
                        "Unable to Perform Your Request.Server Is Temporarily  Unreachable! Please Try Later.",
                        Toast.LENGTH_LONG).show();
            } 
            else{
                if(pErrorFlag.equals("N"))
                    Toast.makeText(getApplicationContext(),"Sign Up successfully done ", Toast.LENGTH_LONG).show();
                else if( pErrorFlag.equals("Y") )
                    Toast.makeText(getApplicationContext(), pErrorMessage, Toast.LENGTH_LONG).show();
            }   
        }

        @Override
        protected String doInBackground(String... args) {
            // TODO Auto-generated method stub

            List<NameValuePair> params = new ArrayList<NameValuePair>(); 
//          params.add(new BasicNameValuePair("pDeviceId",deviceId_str));   
//          params.add(new BasicNameValuePair("pMobileNo",mobile_no_str)); 
//          params.add(new BasicNameValuePair("pUserId",user_id_str)); 
//          params.add(new BasicNameValuePair("pPassword",password_str)); 
//          params.add(new BasicNameValuePair("pPinCode",pin_code_str));

//          params.add(new BasicNameValuePair("pDeviceId","1"));   
//          params.add(new BasicNameValuePair("pMobileNo","1")); 
//          params.add(new BasicNameValuePair("pUserId","1")); 
//          params.add(new BasicNameValuePair("pPassword","1")); 
//          params.add(new BasicNameValuePair("pPinCode","1"));
//          
            json = jsonParser.makeHttpRequest(url_sign_up_execute, "POST", params);

            // Log.d("All Login Responese: ", json.toString());

            try {
                if (json != null) {
                    jsonArray = json.getJSONArray(TAG_SIGN_UP);
                    for (int i = 0; i < jsonArray.length(); i++) {
                        JSONObject c = jsonArray.getJSONObject(i);

                        pErrorFlag = c.getString(TAG_ERROR_FLAG);
                        pErrorMessage = c.getString(TAG_ERROR_MESSAGE) ;

                    }
                    // Log.d("error Code", errorCode);
                } else {
                     Log.d("Server Unreachable",
                     "Unable to Perform Your request.Server Is Unreachable! Please Try Later.");
                }
            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

            return null;
        }
    }

我正在向“http://10.11.201.84:8084//ConnectionToOracle/Sign_Up_Servlet”url 发出 http 请求。但我得到 json 值 null 。为什么 ?我该如何解决这个错误?

最佳答案

尝试使用“http://10.11.201.84:8084/ConnectionToOracle/Sign_Up_Servlet”而不是“http://10.11.201.84:8084//ConnectionToOracle/Sign_Up_Servlet”。可能问题是端口号后面多了一个“/”......

关于java - Android 中 makeHttpRequest 调用中的 json 为 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37236507/

相关文章:

java - 计算 SHA-2 或 SHA-3 哈希值

java - 找到分形并显示它的工作原理,例如 5*4*3*2*1=120

Android:静态方法中的 getString(R.string)

android - UIAutomator 测试的安全异常

android - 与网络同步的应用程序

Java多线程防止两个函数同时运行

java - 确定性生成 RSA 加密 key 对

Mac 上的 Android SDK 路径丢失

c# - jQuery REST POST JSON 列表<对象>

jquery - 在 jQuery 中过滤具有多个记录 ID 的分层 JSON 数据