1

この質問について1つのスレッドを見つけましたが、これは部分的に質問に答えましたが、詳細が必要になる可能性があります。

現在、AndroidアプリでBlobStoreを使用しようとしていますが、501エラー以外は取得できません(HTTPサーバーはリクエストを処理できません)。

彼は私のコードです;

HttpPost httpPostImg = new HttpPost(url);
Header header = new BasicHeader("Content-Type", "multipart/form-data");
Header h = new BasicHeader("Connection", "keep-alive");             
MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
FormBodyPart form = new FormBodyPart("myFile",new ByteArrayBody(image,"multipart/form- data","pict.jpeg"));
entity.addPart(form);
httpPostImg.setEntity(entity);
httpPostImg.setHeader(header);
httpPostImg.setHeader(h);
response = httpClient.execute(httpPostImg);
processResponse(response);

非常にうまく機能しているGETリクエストによってURLを取得します。また、ByteArrayBodyを含むFormBodyPartを試し、ByteArrayBodyのmimeタイプを「multipart / form-data」に設定しようとしましたが、何も機能しませんでした。私は常に501エラーを受け取ります(サーバーはあなたのリクエストを処理できません)。

ありがとう、すべての答えはありがたいです。

4

2 に答える 2

3

さて、いくつかの検索の後、ここに解決策があります;

ヘッダーが期待どおりに機能していないようですので、削除しました。

HttpPost httppost = new HttpPost(url);
MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
entity.addPart("data", new ByteArrayBody(image,"image/jpeg","avatar.jpg"));
httppost.setEntity(entity);
response = httpClient.execute(httppost);
processResponse(response);
于 2011-05-31T16:20:54.700 に答える
1

以下を使用しましたが、うまくいきました。

これは、gzip コンテンツとして投稿する場合の例です。

ByteArrayOutputStream baos = new ByteArrayOutputStream();
    GZIPOutputStream gzos = null;
    try {
        gzos = new GZIPOutputStream(baos);
        gzos.write(xml.getBytes());
    } finally {
        if (gzos != null)
            try {
                gzos.close();
            } catch (IOException ex) {
            }
    }

    byte[] fooGzippedBytes = baos.toByteArray();
    MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
    entity.addPart("name", new ByteArrayBody(fooGzippedBytes,"application/x-gzip", "filename"));

    httpPost.setEntity(entity);
于 2012-09-11T18:48:39.747 に答える