我尝试在 Volley 上使用 GET,但我需要向 application/json
发送请求。
我查看了一些答案,我尝试使用 jsonBody
,但它显示错误:
空 com.android.volley.ServerError
这是我的代码:
public class MainActivity extends AppCompatActivity {
String url = "http://114.35.246.42:2212/MobileApp/DEST_WebService.asmx/GetNews";
JSONObject jsonBody;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
try {
//I try to use this for send Header is application/json
jsonBody = new JSONObject("{\"type\":\"example\"}");
} catch (JSONException ex) {
ex.printStackTrace();
}
RequestQueue mQueue = Volley.newRequestQueue(getApplicationContext());
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(url, jsonBody,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.d("TAG", response.toString());
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e("TAG", error.getMessage(), error);
}
});
mQueue.add(jsonObjectRequest);
}
}
有没有人可以教我如何解决这个问题,我们将不胜感激。
这是我的网址: String url = "http://114.35.246.42:2212/MobileApp/DEST_WebService.asmx/GetNews";
原文由 Morton 发布,翻译遵循 CC BY-SA 4.0 许可协议
在你的实施