kullanıyorum, sunucuya Files
gönderin. Aşağıdaki kodu kullanıyorum:getParams, StringRequest Android'de arama yapmıyor
final MultipartEntityBuilder mHttpEntity = buildMultipartEntity(files_to_upload, params);
Response.Listener<String> rListner = new Response.Listener<String>() {
@Override
public void onResponse(String response) {
if(response != null) {
Intent intent = new Intent(Constants.ACTION_RESPONSE_RECEIVED);
intent.putExtra(Constants.RESPONSE, response);
intent.putExtra(SignupActivity.EXTRA_ACTION_RESPONSE, SignupActivity.EXTRA_SIGNUP_DATA);
LocalBroadcastManager.getInstance(MyApplication.getContext()).sendBroadcast(intent);
}
}
};
Response.ErrorListener errorListner = new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Intent intent = new Intent(Constants.ACTION_RESPONSE_RECEIVED);
LocalBroadcastManager.getInstance(MyApplication.getContext()).sendBroadcast(intent);
if(error != null && error.getMessage() != null) {
// Toast.makeText(MyApplication.getContext(), error.getMessage(), Toast.LENGTH_SHORT).show();
}
else {
Log.i(TAG, "postRequestToServer: onErrorResponse : error message null");
}
}
};
StringRequest jsonObjectRequest = new StringRequest(Request.Method.POST, url, rListner, errorListner)
{
@Override
protected Map<String, String> getParams() throws AuthFailureError {
return params;
}
// @Override
// public Map<String, String> getHeaders() throws AuthFailureError {
// return params;
// }
@Override
public String getBodyContentType() {
return mHttpEntity.build().getContentType().getValue();
}
//
@Override
public byte[] getBody() throws AuthFailureError {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
try {
mHttpEntity.build().writeTo(bos);
} catch (IOException e) {
VolleyLog.e("IOException writing to ByteArrayOutputStream");
}
return bos.toByteArray();
}
};
private MultipartEntityBuilder buildMultipartEntity(String files_to_upload, HashMap<String, String> params) {
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
String[] arr_files = files_to_upload.split("##");
for(int i = 0; i < arr_files.length; i++) {
String filePath = arr_files[i];
if(filePath == null || filePath.length() == 0)
continue;
File file = new File(filePath);
String extension = MimeTypeMap.getFileExtensionFromUrl(arr_files[i]);
String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
builder.addBinaryBody("userfile", file, ContentType.create(mimeType), file.getName());
// builder.addPart("userfile", new FileBody(file));
}
try {
for (String key: params.keySet())
builder.addPart(key, new StringBody(params.get(key)));
} catch (UnsupportedEncodingException e) {
VolleyLog.e("UnsupportedEncodingException");
}
return builder;
}
Ama mesele getParams
çağrılan değil mi. Sunucu parametreler bekliyor, ben EntityBuilder
kullanarak göndermeye çalıştı ama hala parametreleri gönderme hataları yaşıyorum.
Lütfen herkesin bana StringRequest with Parameters
kullanarak nasıl yükleme yapabilirim?
Bildiğim kadarıyla sorunuzu anladım olarak :: Bir 'StringRequest' yapmak için Voleybolu kullandığınızda, bir HTTP GET yapma yanıt olarak tex/düz bekliyoruz. .. Bir POST olarak değiştirdiğinizde, ilgili içerik için [bu bağlantıyı kontrol edebilirsiniz] (http://stackoverflow.com/a/16795805/4903925) ... – Bonatti
Hayır, verileri göndermek için yazı kullanıyorum. 'getParams'ı geçersiz kıldığım zaman çağrılmıyor getBody()' 'Parameters' –