Android 使用HTTP Post多部分实体发送视频

Android 使用HTTP Post多部分实体发送视频,android,http-post,Android,Http Post,我想要的我想要从SD卡向服务器发送视频。我还想发送一些参数/值 我试过了我试过以下代码: public String SendToServer(String aUrl,File aFile) { HttpClient httpClient = new DefaultHttpClient(); HttpPost httpPost = new HttpPost(aUrl); try { Multipa

我想要的我想要从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);

我没有得到任何例外,没有任何回应,什么都没有。有谁能告诉我,这里有什么问题吗?

如果想以内容或esle的形式发送,请尝试使用这种方式,我将在今晚之前上传项目

        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost(url);
        InputStreamEntity reqEntity = new InputStreamEntity(new FileInputStream(filePath), -1);
        reqEntity.setContentType("binary/octet-stream");
        reqEntity.setChunked(true); // Send in multiple parts if needed
        httppost.setEntity(reqEntity);
        HttpResponse response = httpclient.execute(httppost);

我问题中的上述代码是完美的,但我有网络问题。我的设备已连接到热点(连接软件)。当我连接到原始网络时,这个代码工作得非常完美


我建议大家千万不要信任热点的这种功能。

您是否设置了internet权限,或者看到多方jar文件有一些依赖关系,所以您是否要导入它们……?@Khawar您是否检查了服务器日志?@Vipin是的,我已设置了权限,您能否进一步解释一下这种依赖关系?也许这就是问题所在。我不知道。@Gaurav我没有这个服务器。服务器返回一个包含错误的XML(如果有),但没有响应和异常。@Khawar我希望您使用的是apache-mime4j、httpclient、httpcore和HttpTime类,而这些类又需要其他类,如果问题仍然存在,我会将代码和我用来上传图像的代码发送到服务器……但我也想发送参数,否则我会从服务器得到错误。如何使用此代码发送“BasicNameValuePair”(“视频[标题],“testvideo”)?您可以轻松添加BasicNameValuePair,现在使用此库非常感谢这些库。我已经把它们都包括进去了。你能给我发一个代码,我可以把文件和字符串参数一起发送吗?这是我试过的另一个代码,用我的替换库,看起来你想发送一个可以用httppost发送的参数,比如你的url+“/AdServer/getvideooverlalog?imei=“+WatchDogService.imei+”&data=“+data.I,你怎么知道你在一个热点?