我需要使用凌空库2个文件发送到服务器的Android。还有就是它是如何工作以及在邮差的例子:我需要重现这个机器人正好POST调用。请大家现在看看我的代码(没有工作):
JsonObjectRequest sr = new JsonObjectRequest(Request.Method.POST, URL, new JSONObject(params), new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.i("Response", response.toString());
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e("VOLLEY", error.toString());
}
}){
@Override
protected Map<String,String> getParams(){
Map<String,String> params = new HashMap<>();
params.put("Urine", "test");
return params;
}
@Override
public Map<String, String> getHeaders() {
Map<String,String> params = new HashMap<>();
params.put("Authorization", "token");
return params;
}
@Override
public String getBodyContentType() {
return "application/x-www-form-urlencoded; charset=utf-8";
}
@Override
public byte[] getBody() {
int size = (int) file.length();
byte[] bytes = new byte[size];
try {
BufferedInputStream buf = new BufferedInputStream(new FileInputStream(file));
buf.read(bytes, 0, bytes.length);
buf.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return bytes;
}
@Override
protected Response<JSONObject> parseNetworkResponse(NetworkResponse response) {
byte[] data = response.data;
String message = new String(data);
Log.i("parseNetworkResponse", String.valueOf(message));
return super.parseNetworkResponse(response);
}
};
我怎样才能实现这个用排球库?谢谢。