how to httpput the image on a remote server from android
I have tried with following code , but its not working
F开发者_运维问答ile file= new File(filename);
byte[] data = new byte[(int) file.length()];
FileInputStream fileInputStream = new FileInputStream(file);
URL url = new URL("http://www.example.com/resource");
HttpClient client = new DefaultHttpClient();
HttpPut put= new HttpPut(url);
for (int i = 0; i pairs = new ArrayList();
pairs.add(new BasicNameValuePair("Data", data));
put.setEntity(new UrlEncodedFormEntity(pairs));
HttpResponse response = client.execute(put);
I could not able to PUT the data on the server I have also tried with HttpsURLConnection but its getting uploaded.
After setting the content length I am able to do HTTP put , with the help of HttpURLConnection as follows
https.setRequestProperty("Content-Type", "image/jpeg");
https.setRequestProperty("Content-Length", "" + file.length());
精彩评论