2016-04-27 11 views

答えて

0

djodjoとしてStringRequestを使用する必要があります。確かにここAndroid Volley POST string in body

@Override 
       public byte[] getBody() throws AuthFailureError { 
        String httpPostBody="your body as string"; 
        // usually you'd have a field with some values you'd want to escape, you need to do it yourself if overriding getBody. here's how you do it 
        try { 
         httpPostBody=httpPostBody+"&randomFieldFilledWithAwkwardCharacters="+ URLEncoder.encode("{{%stuffToBe Escaped/","UTF-8"); 
        } catch (UnsupportedEncodingException exception) { 
         Log.e("ERROR", "exception", exception); 
         // return null and don't pass any POST string if you encounter encoding error 
         return null; 
        } 
        return httpPostBody.getBytes(); 
       } 
+0

する必要はありません。ボレーはそれらを扱うことができます。私の更新された答えを確認してください。 – djodjo

1

例:

final TextView mTextView = (TextView) findViewById(R.id.text); 
... 

// Instantiate the RequestQueue. 
RequestQueue queue = Volley.newRequestQueue(this); 
String url ="http://www.google.com"; 

// Request a string response from the provided URL. 
StringRequest stringRequest = new StringRequest(Request.Method.GET, url, 
      new Response.Listener<String>() { 
    @Override 
    public void onResponse(String response) { 
     // Display the first 500 characters of the response string. 
     mTextView.setText("Response is: "+ response.substring(0,500)); 
    } 
}, new Response.ErrorListener() { 
    @Override 
    public void onErrorResponse(VolleyError error) { 
     mTextView.setText("That didn't work!"); 
    } 
}); 
// Add the request to the RequestQueue. 
queue.add(stringRequest); 

チェックthe source and more info here

** UPDATE:**あなたのparams追加する必要がある場合は、単にgetParams()

例を上書きすることができます。

@Override 
protected Map<String, String> getParams() throws AuthFailureError { 
     Map<String, String> params = new HashMap<String, String>(); 
     params.put("param1", "val1"); 
     params.put("randomFieldFilledWithAwkwardCharacters","{{%stuffToBe Escaped/"); 
     return params; 
    } 

あなたは無効にする必要はありませんgetBodyあなたのelfは、Volleyがあなたのためにこれをやっているので、特別な文字をエンコードしません。

+0

文字列のリクエストから取ら - もgetBodyメソッドのオーバーライドする必要があります。 public byte [] getBody() – BoazGarty

+0

を無効にする必要もあります。あなたは何をしたいのかを明確にしていませんでした。アップデートを確認してください。 – djodjo

関連する問題