我試圖使用httppost連接到服務器,但由於某些錯誤我無法連接。 這是我的Android代碼:Httppost不工作 - 在Android中獲取html響應而不是JSON
我打電話一次執行方法。我得到這樣的輸出:
https://s23.postimg.org/47dwhsxvf/Screenshot_2016_12_24_11_05_49_com_spellbee_admi.png
PLSZ幫助!
我試圖使用httppost連接到服務器,但由於某些錯誤我無法連接。 這是我的Android代碼:Httppost不工作 - 在Android中獲取html響應而不是JSON
我打電話一次執行方法。我得到這樣的輸出:
https://s23.postimg.org/47dwhsxvf/Screenshot_2016_12_24_11_05_49_com_spellbee_admi.png
PLSZ幫助!
final RequestQueue requestQueue = Volley.newRequestQueue(getApplicationContext()); 最終StringRequest stringRequest =新StringRequest(Request.Method.POST,Appconfig.Url,新Response.Listener(){ @覆蓋 公共無效onResponse(字符串響應){
//compile 'com.mcxiaoke.volley:library:1.0.19'
// <uses-permission android:name="android.permission.INTERNET"/>
try {
jsonObject = new JSONObject(response);
JSONArray jsonArray = jsonObject.getJSONArray("Bros");
for(int i=0; i<jsonArray.length(); i++) {
JSONObject jsonObject1 = jsonArray.getJSONObject(i);
String SONG_ID = jsonObject1.getString("SONG_ID");
String GroupID = jsonObject1.getString("SONG_NAME");
String SONG_PIC = jsonObject1.getString("SONG_PIC");
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(getApplicationContext(),error.toString(),Toast.LENGTH_LONG).show();
}
}){
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> parms = new HashMap<>();
// parms.put("MessageID",Model.getMESSAGE_ID());
return parms;
}
};
requestQueue.add(stringRequest);
}
你沒有speci fy代碼的作用 –
你沒有說明錯誤 – Aaron
另外聲明服務器端代碼..我們無法確定沒有它的問題.. –
這裏是php代碼 –