我正在使用 volley 從 http url 發(fā)送和檢索 json 數(shù)據(jù),但是當收到響應時,我收到一個空的 toast,url 是正確的,“ http://systems.syspearl.com/api ”,但我沒有收到任何響應。下面是我使用過的代碼。 JSONObject jsonobject = new JSONObject(); jsonobject.put("amount", "500"); jsonobject.put("merchant_id", "104"); jsonobject.put("narrative", "John"); jsonobject.put("reference", "Steven"); JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.POST,url, jsonobject,new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject response) { Toast.makeText(Main9Activity.this, response.toString(), Toast.LENGTH_SHORT).show(); }}, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { Toast.makeText(Main9Activity.this, error.getMessage(), Toast.LENGTH_SHORT).show(); }}) { @Override public Map<String, String> getHeaders() throws AuthFailureError { Map<String,String >headers=new HashMap<String,String>(); headers.put(“Content-Type”, “application/json“); headers.put(“AuthKey”, Auth); return headers;}我研究了這個問題,我發(fā)現(xiàn)的最接近的事情是這個https://stackoverflow.com/a/31613565/7871886遺憾的是,在這篇文章中,選擇的解決方案是使用字符串請求發(fā)送 json,我不能這樣做,因為數(shù)據(jù)必須是以這種精確格式發(fā)送到 url { “amount”:500, “merchant_id”:”104”, “narrative”:”John”, “reference”:”Steven” }后一篇文章中的其他答案還建議在 http 中添加 s,這不是我要發(fā)送到的 url。請?zhí)峁﹨f(xié)助
1 回答

心有法竹
TA貢獻1866條經(jīng)驗 獲得超5個贊
您上面的網(wǎng)址http://systems.syspearl.com/api正在響應找不到網(wǎng)址(404)...可能是您的問題..請檢查您的網(wǎng)址路徑并重試...或者如果您的響應為空可能服務器永遠不會發(fā)送響應......所以你可以檢查郵遞員進行確認

一只甜甜圈
TA貢獻1836條經(jīng)驗 獲得超5個贊
url http://systems.syspearl.com/api顯示錯誤......我建議首先,嘗試從文檔https://developer.android.com/training/volley/simple發(fā)出簡單的齊射請求
添加回答
舉報
0/150
提交
取消