簡體   English   中英

如何將圖像從android http放到遠程服務器上

[英]how to httpput the image on a remote server from android

我已經嘗試使用以下代碼,但無法正常工作

File 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);

我無法使用HttpsURLConnection嘗試在服務器上放置數據,但已將其上傳。

設置內容長度后,我可以在HttpURLConnection的幫助下進行HTTP put,如下所示

https.setRequestProperty("Content-Type", "image/jpeg");
https.setRequestProperty("Content-Length", "" + file.length());

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM