请教大神 为何我采用post的方式发送json给PHP 他那边 收不到数据列 ?

时间:2022-10-16 20:25:39
请教大神 为何我采用post的方式发送json给PHP 他那边 收不到数据列  他那边收不到数据  还给我返了一个json 然后我解析 却是 系统错误? 以下是我代码 和日志


代码:

/**
 * 用户注册请求
 * 
 * @param key
 */
@SuppressLint("ShowToast")
private void RegisterPOST(final String masterkey, final String key) {
new Thread() {
Message msg = Message.obtain();

public void run() {
URL url = null;
HttpPost httpRequest = null;
List<NameValuePair> params = null;
HttpResponse httpResponse = null;
String phone = et_phone.getText().toString();
String pwd = et_pwd.getText().toString();

data = "MemberPhone=" + phone + "&MemberLoginPass=" + pwd;
System.out.println("用户名+密码=" + data);

// 两次加密
String str = Demo.getEncrypt(firstKey, masterkey, data);
System.out.println("两次加密的数据=" + str);

// MD5加密
String paper = Md5.getMd5(md5Key);
System.out.println("mD5加密的数据=" + paper);
try {
url = new URL(getString(R.string.registerurl));

// 封装数据
JSONObject register = new JSONObject();
register.put("data", str);
register.put("paper", paper);
register.put("main", key);
System.out.println("封装的json=" + register);
System.out.println("封装的标识key=" + key);
String content = String.valueOf(register);
System.out.println("Json封装后的数据=" + content);

HttpURLConnection conn = (HttpURLConnection) url
.openConnection();
conn.setConnectTimeout(5000);
conn.setDoOutput(true);
conn.setRequestMethod("POST");
conn.setRequestProperty("ser-Agent", "Fiddler");
conn.setRequestProperty("Content-Type", "application/json");
OutputStream os = conn.getOutputStream();
os.write(content.getBytes());
os.close();
int code = conn.getResponseCode();
if (code == 200) {
InputStream is = conn.getInputStream();
String json = NetUtils.readString(is);
JSONObject jsonObject = new JSONObject(json);
System.out.println("服务器返回的json=" + jsonObject);
String data = (String) jsonObject.get("data");
System.out.println("返回得到的data=" + data);
String newmaskey = (String) jsonObject.get("main");
System.out.println("返回得到的main=" + masterkey);

httpRequest = new HttpPost(getString(R.string.posturl));
params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("key", newmaskey));

httpRequest.setEntity(new UrlEncodedFormEntity(params,
HTTP.UTF_8));
httpResponse = new DefaultHttpClient()
.execute(httpRequest);
if (httpResponse.getStatusLine().getStatusCode() == 200) {
String strResult = EntityUtils
.toString(httpResponse.getEntity());

JSONObject lastobj = new JSONObject(strResult);
System.out.println("通过main请求得到的json=" + lastobj);
String lastKey = (String) lastobj.get("masterkey");

System.out.println("解析json得到临时key=" + lastKey);

String name = Demo.getDecrypt(data, lastKey,
firstKey);
System.out.println("手机号=" + name);

msg.what = REGISTER_KEY;
msg.obj = name;

} else {
Toast.makeText(MainActivity.this, "请求数据失败!", 1)
.show();
}

} else {
Toast.makeText(MainActivity.this, "请求数据失败!", 1).show();
}

} catch (Exception e1) {
e1.printStackTrace();
} finally {
handler.sendMessage(msg);
}
};
}.start();
}


日志信息:

09-27 15:36:40.456: I/System.out(24790): 200
09-27 15:36:40.461: I/System.out(24790): 第一次请求得到的json={"key":"10533ffd149c6ca79c5efeaa66de3276"}
09-27 15:36:40.461: I/System.out(24790): 请求setMasterKey得到的key=10533ffd149c6ca79c5efeaa66de3276
09-27 15:36:40.701: I/System.out(24790): Thread-3761 calls detatch()
09-27 15:36:40.701: I/System.out(24790): 用第一次请求得到的key请求得到临时key={"masterkey":"8efab3278dcde217"}
09-27 15:36:40.706: I/System.out(24790): 用户名+密码=MemberPhone=1850785&MemberLoginPass=123456
09-27 15:36:40.706: I/System.out(24790): 请求Getmasterkey得到的key=8efab3278dcde217
09-27 15:36:40.706: I/System.out(24790): 一次加密的数据=zYKD4KaRUmesAhjowzlBUC8T1yI36VuJQ00+enRIW8TNYpm/UHM3h8sFWyNhwzrG
09-27 15:36:40.706: I/System.out(24790): 二次加密的数据=PNBSTbmSIV8KRoGkSSK6gLZ0VreLEppttxKMMxbovyIpbidxTlckiYvhvNHHhqqXyCOqs7EAIm75
09-27 15:36:40.706: I/System.out(24790): 2XIqdOUHOQ==
09-27 15:36:40.706: I/System.out(24790): 两次加密的数据=PNBSTbmSIV8KRoGkSSK6gLZ0VreLEppttxKMMxbovyIpbidxTlckiYvhvNHHhqqXyCOqs7EAIm75
09-27 15:36:40.706: I/System.out(24790): 2XIqdOUHOQ==
09-27 15:36:40.706: I/System.out(24790): mD5加密的数据=b94bd10ab2facf42c1c60ab145029a6d
09-27 15:36:40.711: I/System.out(24790): 封装的json={"data":"PNBSTbmSIV8KRoGkSSK6gLZ0VreLEppttxKMMxbovyIpbidxTlckiYvhvNHHhqqXyCOqs7EAIm75\n2XIqdOUHOQ==","paper":"b94bd10ab2facf42c1c60ab145029a6d","main":"10533ffd149c6ca79c5efeaa66de3276"}
09-27 15:36:40.711: I/System.out(24790): 封装的标识key=10533ffd149c6ca79c5efeaa66de3276
09-27 15:36:40.711: I/System.out(24790): Json封装后的数据={"data":"PNBSTbmSIV8KRoGkSSK6gLZ0VreLEppttxKMMxbovyIpbidxTlckiYvhvNHHhqqXyCOqs7EAIm75\n2XIqdOUHOQ==","paper":"b94bd10ab2facf42c1c60ab145029a6d","main":"10533ffd149c6ca79c5efeaa66de3276"}
09-27 15:36:40.861: I/System.out(24790): 服务器返回的json={"data":"odTdiB\/myr1JOiJ4p8wfTzw5U1x1BIVnIjQnN8CN1cd4mCschCgOTY9ZTTGA6McND1X+kN9S0Nnqrm2PeqnxIA==","paper":"b94bd10ab2facf42c1c60ab145029a6d","main":"58791476fefeb40a9d3ac8f33d2a531d"}
09-27 15:36:40.861: I/System.out(24790): 返回得到的data=odTdiB/myr1JOiJ4p8wfTzw5U1x1BIVnIjQnN8CN1cd4mCschCgOTY9ZTTGA6McND1X+kN9S0Nnqrm2PeqnxIA==
09-27 15:36:40.861: I/System.out(24790): 返回得到的main=8efab3278dcde217
09-27 15:36:41.046: I/System.out(24790): Thread-3762 calls detatch()
09-27 15:36:41.046: I/System.out(24790): 通过main请求得到的json={"masterkey":"af58643ea9443ab6"}
09-27 15:36:41.046: I/System.out(24790): 解析json得到临时key=af58643ea9443ab6
09-27 15:36:41.046: I/System.out(24790): 用临时key解密得到的数据=DDHQmain0qMTLaOYGzGnWxfx+3Atazidzw049NKDcumPfREptgcut86VaukLTBzQ
09-27 15:36:41.046: I/System.out(24790): 用固定key解密得到的数据=DDHQmain0qMTLaOYGzGnWxfx+3Atazidzw049NKDcumPfREptgcut86VaukLTBzQ
09-27 15:36:41.046: I/System.out(24790): 手机号={"result":"\u7cfb\u7edf\u5f02\u5e38","state":-1}
09-27 15:36:41.051: I/System.out(24790): name_hone={"result":"\u7cfb\u7edf\u5f02\u5e38","state":-1}

求大神指点 QQ: 995472572  

3 个解决方案

#1


大神你在何方 !

#2


是不是请求 错了?

#3


你加一个os.flush试试

#1


大神你在何方 !

#2


是不是请求 错了?

#3


你加一个os.flush试试