gpt4 book ai didi

android - 如何在 MultipartEntity 中传递字符串变量?

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:41:43 25 4
gpt4 key购买 nike

我在 MultipartEntity 中传递 3 张图像。这很好用,但我不知道如何将 String 值传递给 MultipartEntity。以下是我的代码:

public void executeMultipartPost(Bitmap bm, int i) throws Exception {
try {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
bm.compress(CompressFormat.JPEG, 75, bos);
byte[] data = bos.toByteArray();
HttpClient httpClient = new DefaultHttpClient();
HttpPost postRequest = new HttpPost("http://www.3dsoles.com/droidapp/index.php");

ByteArrayBody bab = new ByteArrayBody(data, "image" + i + ".jpg");
// File file= new File("/mnt/sdcard/forest.png");
// FileBody bin = new FileBody(file);
MultipartEntity reqEntity = new MultipartEntity(
HttpMultipartMode.BROWSER_COMPATIBLE);
reqEntity.addPart("file", bab);
// reqEntity.addPart("userID", Constants.mUserImei);
reqEntity.addPart("photoCaption", new StringBody("sfsdfsdf"));
postRequest.setEntity(reqEntity);
HttpResponse response = httpClient.execute(postRequest);
BufferedReader reader = new BufferedReader(new InputStreamReader(
response.getEntity().getContent(), "UTF-8"));
String sResponse;
StringBuilder s = new StringBuilder();
while ((sResponse = reader.readLine()) != null) {
s = s.append(sResponse);
}
System.out.println("Response: " + s);
} catch (Exception e) {
BugSenseHandler.log("Uploading File", e);
}
}

最佳答案

请参阅此链接以获取 additional jar files 你应该添加..

HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://www.tumblr.com/api/write");

try
{
MultipartEntity entity = new MultipartEntity();
entity.addPart("type",new StringBody("yourstring"));
httppost.setEntity(entity);
HttpResponse response = httpclient.execute(httppost);
}
catch (ClientProtocolException e)
{ }
catch (IOException e)
{ }

关于android - 如何在 MultipartEntity 中传递字符串变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9971628/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com