2

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);

例外はなく、応答もまったくありません。誰かが私を案内してくれますか、ここの問題は何ですか?

4

2 に答える 2

1

コンテンツまたはメールとして送信したい場合は、この方法を使用してみてください。今夜までにプロジェクトをアップロードします

        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);
于 2012-04-20T13:33:32.283 に答える