安卓与php进行交互的问题
发布时间:2022-10-31 12:46:22 所属栏目:PHP教程 来源:
导读: 因为公司保密协议,php网址不方便给,见谅。
用Postman查看该php网站是这样的
图片说明
我的代码是这样的:
public class JSONExchanger extends AsyncTask {
String u
用Postman查看该php网站是这样的
图片说明
我的代码是这样的:
public class JSONExchanger extends AsyncTask {
String u
|
因为公司保密协议,php网址不方便给,见谅。 用Postman查看该php网站是这样的 图片说明 我的代码是这样的: public class JSONExchanger extends AsyncTask { String url ="login.php"; @Override protected JSONObject doInBackground(JSONObject... jsonObjects) { JSONObject jsonObject = jsonObjects[0]; HttpClient httpClient = new DefaultHttpClient(); //HttpConnectionParams.setConnectionTimeout(httpClient.getParams(), 100000); JSONObject response = null; HttpPost httpPost = new HttpPost(url); try { Log.i("jsonObject",jsonObject.toString()); StringEntity stringEntity = new StringEntity(jsonObject.toString()); jquery ajax与php交互_php交互_php与html怎么实现交互 // httpPost.addHeader("username","password"); httpPost.setEntity(stringEntity); HttpResponse httpResponse = httpClient.execute(httpPost); String Server_Response = org.apache.http.util.EntityUtils.toString(httpResponse.getEntity()); response = new JSONObject(Server_Response); Log.i("Response", Server_Response); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (JSONException e) { e.printStackTrace(); } return response; jquery ajax与php交互_php交互_php与html怎么实现交互 } } 然后在MainActivity中php交互, try { JSONObject toSend = new JSONObject(); toSend.put("username","abc"); toSend.put("password","bcd"); JSONExchanger jsonExchanger = new JSONExchanger(); jsonExchanger.execute(new JSONObject[]{toSend}); } catch (JSONException e) { e.printStackTrace(); } 卤煮之前没有用过安卓和PHP进行交互今天现学的,还请各位大神不吝赐教,谢谢大家!! (编辑:我爱资讯网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
站长推荐


