2015-03-02 63 views
1

有什麼方法可以用Volley發送字節數組?用Volley發送ByteArray

現在我使用的是這樣的:

post.setEntity(new ByteArrayEntity(rawPacket.toByteArray())); 
try { 
    response = client.execute(post); 
} catch (IOException e) { 
    e.printStackTrace(); 
} 

有這樣的事情在排球?有一種方法可以通過POST/GET請求傳遞要發送的自定義對象?

protected Map<String, String> getParams() throws AuthFailureError { 
      HashMap<String, String> params = new HashMap<>(); 
      params.put("RawPacket", rawPacket.toByteArray().toString()); 
      return params; 
     } 

我需要像下面protected Map<String, ByteArray> getParams()

回答

0

見代碼:

public class JsonArrayRequest extends JsonRequest<JSONArray> { 
/** 
* Creates a new request. 
* @param url URL to fetch the JSON from 
* @param listener Listener to receive the JSON response 
* @param errorListener Error listener, or null to ignore errors. 
*/ 
public JsonArrayRequest(String url, Listener<JSONArray> listener, ErrorListener errorListener) { 
    super(Method.GET, url, null, listener, errorListener); 
} 

你必須創建JsonRequest的子類,並使用它。

見相關鏈接: Volley - Sending a POST request using JSONArrayRequest

可能還需要爲Base64編碼的字節,並將其添加到JsonArray。

+0

是的,但我怎麼能把自定義對象放在我發送的參數? – 2015-03-02 11:14:55

+0

使用JsonArray,你幾乎可以存儲任何值 – 2015-03-02 12:09:03

+0

如何用ByteArray參數構建Json? – 2015-03-02 12:22:12

2

我發現解決方案覆蓋函數public byte[] getBody()發送自定義數據,我應該更好地閱讀文檔!

相關問題