【发布时间】:2012-04-20 12:41:28
【问题描述】:
我想要什么我想将视频从我的 SD 卡发送到服务器。我也想用它发送一些参数/值。
我试过了我试过下面的代码:
public String SendToServer(String aUrl,File aFile)
{
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(aUrl);
try
{
MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
entity.addPart("file", new FileBody(aFile));
entity.addPart("video[title]", new StringBody("testVideo"));
entity.addPart("video[type]", new StringBody("1"));
httpPost.setEntity(entity);
HttpContext localContext = new BasicHttpContext();
// Bind custom cookie store to the local context
localContext.setAttribute(ClientContext.COOKIE_STORE, Globals.sessionCookie);
HttpResponse response = httpClient.execute(httpPost, localContext);
HttpEntity resEntity = response.getEntity();
String Response = "";
if (response != null)
{
Response = EntityUtils.toString(resEntity);
}
return Response;
}
catch (IOException e)
{
e.printStackTrace();
}
return "Exception";
}
什么问题运行这段代码时,卡在这一行
HttpResponse response = httpClient.execute(httpPost, localContext);
我没有例外,没有任何回应。谁能指导我,这里有什么问题?
【问题讨论】:
-
您是否设置了互联网权限或看到多方jar文件有一些依赖关系,所以您是否正在导入它们.....?
-
@Khawar 你检查你的服务器日志了吗?
-
@Vipin 是的,我已经设置了权限,你能解释一下这个依赖关系吗?可能这就是问题所在。我不知道。
-
@Gaurav 我没有这台服务器。如果有错误,服务器会返回给我一个带有错误的 XML,但没有响应和异常。
-
@Khawar 我希望你正在使用这个 apache-mime4j、httpclient、httpcore 和 httpmime 类,这些类又需要其他类,如果问题仍然存在,我将发送代码并且我用来上传图像到服务器.......