我想將圖片上傳到webService,但我無法做到這一點,我在這裏和在互聯網上搜索了很多話題,但無法找到好的解決方案。我如何將圖片上傳到.net WebService從Android
當我運行此代碼時,我得到錯誤的請求錯誤。
更新:我使用了一些代碼是在這個環節:Uploading MS Word files from Android to .Net WCF?
但給我FileNotFoundException異常,但我的文件路徑是:/mnt/sdcard/ImageDir/images/ilan_1360917248037__thumb_.jpeg
這裏是我的代碼,我想:
public static String imgUpload(String url, List<NameValuePair> list, List<String> images){
String result = Constants.EMPTY;
Bitmap bm;
HttpParams httpParams = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpParams, ServiceConstant.TIMEOUT_MILLISEC);
HttpConnectionParams.setSoTimeout(httpParams, ServiceConstant.TIMEOUT_MILLISEC);
HttpParams p = new BasicHttpParams();
HttpClient httpclient = new DefaultHttpClient(p);
HttpPost httppost = new HttpPost(url);
String resimYol = images.get(0);
resimYol = resimYol.replace("file:///", "/");
bm = BitmapFactory.decodeFile(resimYol);
Log.d("RESIL_YOL", resimYol.toString());
try{
ByteArrayBody bab = new ByteArrayBody(b, resimYol);
ResponseHandler<String> responseHandler = new BasicResponseHandler();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
bm.compress(CompressFormat.JPEG, 100, bos);
byte[] data = bos.toByteArray();
ByteArrayBody bab = new ByteArrayBody(data, resimYol);
MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
httppost.setEntity(reqEntity);
result = httpclient.execute(httppost,responseHandler);
}
catch (Exception e) {
// handle exception here
Log.e(e.getClass().getName(), e.getMessage());
}
return result;
}
這裏是我的logcat:
02-12 11:43:07.467: E/org.apache.http.client.HttpResponseException(19112): Bad Request
可以請你把日誌貓? – 2013-02-12 10:15:25
好吧,我把logcat。 – 2013-02-12 10:16:35
錯誤的請求是服務器說它不喜歡你的POST中的某些東西。檢查服務器是否有某些東西不想獲取請求。 – 2013-02-12 10:40:29