0
我更改了我的安全HttpPost
。我將如何實現使用多部分表單數據?
我能夠讓應用程序加載/拍照,但它無法與API交談,因爲API使用了不同的檢索方法。
我確實有一個多部分編碼的例子,但不確定如何實現這一點。 我正在做什麼/我需要做什麼的例子可以找到here。
我將如何實現使用多部分表單數據?
protected Object doInBackground(Object... arg0) {
Bitmap bitmapOrg = ((Main) parentActivity).mPhoto;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
// compress bitmap into the byte array output stream
bitmapOrg.compress(Bitmap.CompressFormat.JPEG, 75, baos);
// form byte array out of byte array output stream
byte[] ba = baos.toByteArray();
String encodedImage = Base64.encodeBytes(ba);
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(
"-----------------------------------");
// Add your data
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
nameValuePairs.add(new BasicNameValuePair("image", encodedImage));
try {
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
InputStream inputstream = entity.getContent();
StringBuilder sb = new StringBuilder();
BufferedReader reader = new BufferedReader(
new InputStreamReader(inputstream));
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
results = sb.toString();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}