如何从Android的值传递到PHP? [英] How to pass the value into php from android?
本文介绍了如何从Android的值传递到PHP?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我现在面临的问题与Android的值传递到PHP脚本。
我要的 questionid
来传递到PHP脚本 url_get_ansurl
但我不能传递值。
如何做到这一点?请指引我。
多谢了。
尝试{ INT成功= json.getInt(TAG_SUCCESS); 如果(成功== 1){ 的System.out.println(成功); 组= json.getJSONArray(TAG_GROUP); 的System.out.println(结果成功++++组); 的for(int i = 0; I< groups.length();我++){ JSONObject的C = groups.getJSONObject(我); 字符串的问题= c.getString(TAG_QUES); 的System.out.println(检查::+问题); ques1.add(问题); 字符串questionid = c.getString(TAG_QUESID); 的System.out.println(检查::+ questionid); ID = questionid; quesid.add(questionid); } } 其他 { showAlert(); } }赶上(JSONException E){ 的System.out.println(错误+ e.toString()); } 名单<的NameValuePair> params1 =新的ArrayList<的NameValuePair>(); params1.add(新BasicNameValuePair(QID,QID)); JSON = jsonParser.makeHtt prequest(url_get_ansurl,GET,params1); 的System.out.println(疑问句的价值得到了); Log.d(所有组,json.toString()); 的System.out.println(问题); 尝试 { INT成功= json.getInt(TAG_SUCCESS); 的System.out.println(成功); 如果(成功== 1){ 的System.out.println(成功); 组= json.getJSONArray(TAG_GROUP); 的System.out.println(结果成功++++组); 的for(int i = 0; I< groups.length();我++){ JSONObject的C = groups.getJSONObject(我); 字符串的答案= c.getString(TAG_ANSW); 的System.out.println(检查::+答案); answ1.add(答案); } } 其他 { showAlert(); } }赶上(JSONException E){ 的System.out.println(错误+ e.toString()); } 保护无效onPostExecute(字符串file_url){ pDialog.dismiss(); ques1 =新的ArrayList<字符串>(新的ArrayList<字符串>(ques1)); // J = 0; TextView的txtque =(TextView中)findViewById(R.id.que_txt); txtque.setText(ques1.get(J));
解决方案
您可以通过在POST使用或GET
名单,其中,的NameValuePair> PARAMS =新的ArrayList<的NameValuePair>();
params.add(新BasicNameValuePair(questionid,questionid));
尝试 {
的HttpParams httpParameters =新BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpParameters,10000);
HttpConnectionParams.setSoTimeout(httpParameters,10000);
HttpClient的httpClientpost =新DefaultHttpClient(httpParameters);
// HTTPGET后=新HTTPGET(url_request);
HttpPost后=新HttpPost(url_request);
UrlEn codedFormEntity ENT =新UrlEn codedFormEntity(参数,可以
HTTP.UTF_8);
post.setEntity(ENT);
HTT presponse responsePOST = httpClientpost.execute(后);
HttpEntity resEntity = responsePOST.getEntity();
字符串的GetResponse = EntityUtils.toString(resEntity); //来自服务器的响应
}赶上(IOException异常E){
e.printStackTrace();
}赶上(JSONException E){
e.printStackTrace();
}
I'm facing problem with passing the value to the php script from android.
I want the questionid
to pass into php script url_get_ansurl
but I can't pass the value.
How to do this? Please guide me.
Thanks a lot.
try { int success = json.getInt(TAG_SUCCESS); if (success == 1) { System.out.println("Success"); groups = json.getJSONArray(TAG_GROUP); System.out.println("Result Success+++"+groups); for (int i = 0; i < groups.length();i++) { JSONObject c = groups.getJSONObject(i); String question = c.getString(TAG_QUES); System.out.println("Checking ::"+question); ques1.add(question); String questionid = c.getString(TAG_QUESID); System.out.println("Checking ::"+questionid); id=questionid; quesid.add(questionid); } } else { showAlert(); } } catch (JSONException e) { System.out.println("Error "+e.toString()); } List<NameValuePair> params1 = new ArrayList<NameValuePair>(); params1.add(new BasicNameValuePair("qid", qid)); json = jsonParser.makeHttpRequest(url_get_ansurl, "GET", params1); System.out.println("ques value got"); Log.d("All Groups: ", json.toString()); System.out.println("question"); try { int success = json.getInt(TAG_SUCCESS); System.out.println("Success"); if (success == 1) { System.out.println("Success"); groups = json.getJSONArray(TAG_GROUP); System.out.println("Result Success+++"+groups); for (int i = 0; i < groups.length();i++) { JSONObject c = groups.getJSONObject(i); String answer = c.getString(TAG_ANSW); System.out.println("Checking ::"+answer); answ1.add(answer); } } else { showAlert(); } } catch (JSONException e) { System.out.println("Error "+e.toString()); } protected void onPostExecute(String file_url) { pDialog.dismiss(); ques1=new ArrayList<String>(new ArrayList<String>(ques1)); // j=0; TextView txtque = (TextView) findViewById(R.id.que_txt); txtque.setText(ques1.get(j));
解决方案
You can use this by POST or GET
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("questionid", questionid));
try {
HttpParams httpParameters = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpParameters, 10000);
HttpConnectionParams.setSoTimeout(httpParameters, 10000);
HttpClient httpClientpost = new DefaultHttpClient(httpParameters);
//HttpGet post = new HttpGet(url_request);
HttpPost post = new HttpPost(url_request);
UrlEncodedFormEntity ent = new UrlEncodedFormEntity(params,
HTTP.UTF_8);
post.setEntity(ent);
HttpResponse responsePOST = httpClientpost.execute(post);
HttpEntity resEntity = responsePOST.getEntity();
String getresponse = EntityUtils.toString(resEntity); //Response from the server
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
这篇关于如何从Android的值传递到PHP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文