我对PHP,JavaScript和许多其他脚本语言很有经验,但我没有很多Java或Android的经验.
我正在寻找一种方法将POST数据发送到PHP脚本并显示结果.
我在android中上传图片时遇到问题.
我正在使用apache httpmime 4.1 lib代码是这样的:
MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
reqEntity.addPart("image", new FileBody(new File(AndorraApplication.getPhotosPath() + "/" + entity.getFileName()), "image/jpeg"));
resp = NetworkUtils.sendHttpRequestMultipart(EXPORT_PHOTOS_URI, reqEntity);
Run Code Online (Sandbox Code Playgroud)
NetworkUtils类:
public class NetworkUtils {
public static final int REGISTRATION_TIMEOUT = 3 * 1000;
public static final int WAIT_TIMEOUT = 5 * 1000;
public static HttpResponse sendHttpRequestMultipart(String uri, MultipartEntity entity) {
HttpClient mHttpClient = new DefaultHttpClient();
final HttpParams params = mHttpClient.getParams();
HttpConnectionParams.setConnectionTimeout(params, REGISTRATION_TIMEOUT);
HttpConnectionParams.setSoTimeout(params, WAIT_TIMEOUT);
ConnManagerParams.setTimeout(params, WAIT_TIMEOUT);
HttpPost post = new HttpPost(uri);
post.addHeader(entity.getContentType());
post.setEntity(entity);
HttpResponse resp = …Run Code Online (Sandbox Code Playgroud)