这是mycode,它非常完美,可以在模拟器上运行时在服务器上成功上传,但无法在移动设备上运行。给出任何建议......
public void up()
{
String url ="http://jmhtechsol.com/photoshare/uploads.php?imgname=" + jm +"&uid="+ uid +"&albumnm=" + albumname;
HttpParams httpParameters = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpParameters,3000);
HttpConnectionParams.setSoTimeout(httpParameters,3000);
HttpConnectionParams.setTcpNoDelay(httpParameters, true);
HttpClient client = new DefaultHttpClient(httpParameters);
client.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION,HttpVersion.HTTP_1_1);
// HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(url);
MultipartEntity mpEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
//Path of the file to be uploaded
String filepath = selectedImagePath;
File file = new File(filepath);
ContentBody cbFile = new FileBody(file, "video/mp4");
mpEntity.addPart("uploadedfile", cbFile);
try {
mpEntity.addPart("name", new StringBody("Test", Charset.forName("UTF-8")));
mpEntity.addPart("data", new StringBody("This is test report", Charset.forName("UTF-8")));
post.setEntity(mpEntity);
//Execute the post request
HttpResponse response1 = client.execute(post);
//Get the response from the server
HttpEntity resEntity = response1.getEntity();
String Response=EntityUtils.toString(resEntity);
Log.d("Response:", Response);
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Log.d("UnsupportedEncodingException",e.getMessage());
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Log.d("ClientProtocolException",e.getMessage());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Log.d("IOException",e.getMessage());
}
client.getConnectionManager().shutdown();
}