ich habe den Code hier:
PHP Code:
import java.io.File;
import java.nio.charset.Charset;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.HttpVersion;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.mime.MultipartEntity;
import org.apache.http.entity.mime.content.ContentBody;
import org.apache.http.entity.mime.content.FileBody;
import org.apache.http.entity.mime.content.StringBody;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.CoreProtocolPNames;
import org.apache.http.util.EntityUtils;
public class UploadTest {
public static void main(String[] args) throws Exception {
HttpClient httpclient = new DefaultHttpClient();
httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
HttpPost httppost = new HttpPost("http://uploads.im/api?upload=");
File file = new File("E:/d.jpg");
MultipartEntity mpEntity = new MultipartEntity();
ContentBody cbFile = new FileBody(file);
mpEntity.addPart("file", cbFile);
// mpEntity.addPart( "parameter", new StringBody("format=txt"));
httppost.setEntity(mpEntity);
System.out.println("executing request " + httppost.getRequestLine());
HttpResponse response = httpclient.execute(httppost);
HttpEntity resEntity = response.getEntity();
System.out.println(response.getStatusLine());
if (resEntity != null) {
System.out.println(EntityUtils.toString(resEntity));
}
if (resEntity != null) {
resEntity.consumeContent();
}
httpclient.getConnectionManager().shutdown();
}
}
und der Upload funktioniert auch und ich komme alles zurück wie hier beschrieben
.(Also )
Jetzt will ich aber bloß die ImageUrl und dafür soll ich dem den Parameter "format=txt" () mitgeben.
Da ist mir bloß nicht so ganz klar wie ich das machen muss, der HttpPost wird ja aus meinem MultipartEntity gemacht und eigentlich müsste ich da ja mit dem .addPart einfach noch den Parameter hinzufügen oder?
Habe schon Sachen probiert wie
PHP Code:
mpEntity.addPart( "parameter", new StringBody("format=txt"));






