私はVolleyを使用することをお勧めします。 Volleyは、Androidアプリのネットワーキングをより簡単で重要なものに早くするHTTPライブラリです。 VolleyはGitHubにあります。 GETと
ボレー:POSTと
RequestQueue queue = Volley.newRequestQueue(getContext);
String url = "http://www.someurl.com?param1=value1¶m2=value2"; // your url
StringRequest stringRequest = new StringRequest(Request.Method.GET, url, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
// here you will get the response from the url
Log.d(TAG, response);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
// in case there is error in request, it'll be thrown here
Log.e(TAG, error.toString);
}
});
queue.add(stringRequest);
ボレー:
RequestQueue queue = Volley.newRequestQueue(getContext);
String url = "http://www.someurl.com"; // your url
StringRequest stringRequest = new StringRequest(Request.Method.POST, url, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
// here you will get the response from the url
Log.d(TAG, response);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
// in case there is error in request, it'll be thrown here
Log.e(TAG, error.toString);
}
}){
@Override
protected Map<String,String> getParams(){
// here you add params
Map<String,String> params = new HashMap<>();
params.put("param1", "value1");
params.put("param2", "value2");
return params;
}
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
return super.getHeaders();
}
@Override
public String getBodyContentType() {
return super.getBodyContentType();
}
};
queue.add(stringRequest);
は、より多くのコードを入力してください。 paramsをどのように渡してリクエストしますか? – MaxV
[Android AsyncHttpClient:マルチパートフォームデータをPOSTする方法は?](http://stackoverflow.com/questions/33649852/android-asynchttpclient-how-to-post-multipart-form-data) – MaxV