我对PHP,JavaScript和许多其他脚本语言很有经验,但我没有很多Java或Android的经验.
我正在寻找一种方法将POST数据发送到PHP脚本并显示结果.
我想发送包含电子邮件和姓名等视频和数据的多部分表单.以下是我的代码,它不起作用,没有来自服务器的响应
File file =new File(VideoPath);
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(url);
try {
// Add your data
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("Name", "LDGHT"));
nameValuePairs.add(new BasicNameValuePair("Email", "hhh@example.com"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
httppost.setEntity(new FileEntity(file, "video/mp4"));
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
} catch (IOException e) {
// TODO Auto-generated catch block
}
Run Code Online (Sandbox Code Playgroud)