gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 09:55:48 25 4
gpt4 key购买 nike

我有一个名为 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com