我尝试使用Volley
库并将图像上传到服务器。该库应在独立模式下执行此过程,但收到以下错误消息:
java.net.SocketException:sendto 失败:ECONNRESET(对等方重置连接)
是否可能是服务器端配置错误?我尝试jpeg
使用以下代码上传图片:
private void uploadImage(){
final ProgressDialog loading = ProgressDialog.show(this,"Uploading...","Please wait...",false,false);
StringRequest stringRequest = new StringRequest(Request.Method.POST, UPLOAD_URL,
new Response.Listener<String>() {
@Override
public void onResponse(String s) {
loading.dismiss();
Toast.makeText(PhotoActivity.this, s , Toast.LENGTH_LONG).show();
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError volleyError) {
loading.dismiss();
Toast.makeText(PhotoActivity.this, volleyError.getMessage().toString(), Toast.LENGTH_LONG).show();
}
}){
@Override
protected Map<String, String> getParams() throws AuthFailureError {
String image = getStringImage(bitmap);
String name = editTextName.getText().toString().trim();
Map<String,String> params = new Hashtable<String, String>();
params.put(KEY_IMAGE, image);
params.put(KEY_NAME, name);
return params;
}
};
RequestQueue requestQueue = Volley.newRequestQueue(this);
requestQueue.add(stringRequest);
}