1

我收到以下错误

InvalidPolicyDocument表单内容不符合策略文档中指定的条件。策略文档解析错误:Lexical Error: Unmatched Input: <s>

我调用 HTTPURLConnection 的异步任务如下。multipartv1 类来自这里

在 AsyncTask doinbackground 内部

{multipartv1.addFormField("key", filename_insert_value);
multipartv1.addFormField("bucket", “myapplication”);
multipartv1.addFormField("Content-Type", "image/jpeg");
multipartv1.addFormField("GoogleAccessId", “myapplication@appspot.gserviceaccount.com");
multipartv1.addFormField("acl", "bucket-owner-read");
multipartv1.addFormField("success_action_redirect", "https://myapplication.appspot.com/getpolicydocumentsuccess");
multipartv1.addFormField("success_action_status", "201");
multipartv1.addFormField("x-goog-meta-programname", this.current_program_name);
multipartv1.addFormField("x-goog-meta-membername", this.member_element_id);
multipartv1.addFormField("x-goog-meta-tag1", tag1);
multipartv1.addFormField("x-goog-meta-tag2", tag2);
multipartv1.addFormField("x-goog-meta-tag3", tag3);
multipartv1.addFormField("x-goog-meta-tag4", tag4);
multipartv1.addFormField("x-goog-meta-tag5", tag5);
multipartv1.addFormField("policy", this.policy);
multipartv1.addFormField("signature", this.signature);

multipartv1.addFilePart("file", new File(this.file_absolute_path));

List<String> response_multipart = multipartv1.finish();
Log.e(Tag, "SERVER REPLIED:");
for (String line : response_multipart) {
Log.e(Tag, "Upload Files Response:::" + line);
}

“策略”是使用 Google Cloud Endpoint API 从我的后端(Google App Engine)生成的。这是此处列出的 Google Cloud Storage XML API 支持的政策文档。通过 Web 应用程序访问时,“策略”可以完美运行。

“政策”是这样的——

ewkJCQoJCQkJImV4cGlyYXRpb24iOiAiMjAxNi0wNi0xNlQxMToxMToxMVoiLAoJCQkJImNvbmRpdGlvbnMiOiBbCgkJCQkJWyJzdGFydHMtd2l0aCIsICIka2V5IiwgIiIgXSwKCQkJCQl7ImFjbCI6ICJidWNrZXQtb3duZXItcmVhZCIgfSwKCQkJCQl7ImJ1Y2tldCI6ICJlbmdhZ2VkLXBhcnNlYy02MTIuYXBwc3BvdC5jb20ifSwKCQkJCQl7InN1Y2Nlc3NfYWN0aW9uX3JlZGlyZWN0Ijogc3VjY2Vzc19yZWRpcmVjdCB9LAoJCQkJCXsic3VjY2Vzc19hY3Rpb25fc3RhdHVzIjogIjIwMSJ9LAkJCQoJCQkJCVsiZXEiLCAiJENvbnRlbnQtVHlwZSIsICJpbWFnZS9qcGVnIiBdLAoJCQkJCVsic3RhcnRzLXdpdGgiLCAiJHgtZ29vZy1tZXRhLXByb2dyYW1uYW1lIiwgIiJdLAoJCQkJCVsic3RhcnRzLXdpdGgiLCAiJHgtZ29vZy1tZXRhLW1lbWJlcm5hbWUiLCAiIl0sCgkJCQkJWyJzdGFydHMtd2l0aCIsICIkeC1nb29nLW1ldGEtdGFnMSIsICIiXSwKCQkJCQlbInN0YXJ0cy13aXRoIiwgIiR4LWdvb2ctbWV0YS10YWcyIiwgIiJdLAoJCQkJCVsic3RhcnRzLXdpdGgiLCAiJHgtZ29vZy1tZXRhLXRhZzMiLCAiIl0sCgkJCQkJWyJzdGFydHMtd2l0aCIsICIkeC1nb29nLW1ldGEtdGFnNCIsICIiXSwKCQkJCQlbInN0YXJ0cy13aXRoIiwgIiR4LWdvb2ctbWV0YS10YWc1IiwgIiJdLAoJCQkJCVsiY29udGVudC1sZW5ndGgtcmFuZ2UiLCAwLCAzMDAwMDAwMF0KCQkJCQldCQkJCQoJCQkJfQ==

我担心的是,当我在 HttpURLConnection 中添加“策略”参数时,会出现问题。添加“策略”参数的代码是这样的 -

 public void addFormField(String name, String value) {
            writer.append("--" + boundary).append(LINE_FEED);
            writer.append("Content-Disposition: form-data; name=\"" + name + "\"")
                    .append(LINE_FEED);
            writer.append("Content-Type: text/plain; charset=" + charset).append(
                    LINE_FEED);
            writer.append(LINE_FEED);
            writer.append(value).append(LINE_FEED);
            writer.flush();
        }

HTTP Post 调用在这里 -

public List<String> finish() throws IOException {
        List<String> response = new ArrayList<String>();
        writer.append(LINE_FEED).flush();
        writer.append("--" + boundary + "--").append(LINE_FEED);
        writer.close();

        // checks server's status code first
        int status = httpConn.getResponseCode();
        if (status == HttpURLConnection.HTTP_OK) {
            BufferedReader reader = new BufferedReader(new InputStreamReader(
                    httpConn.getInputStream()));
            String line = null;
            while ((line = reader.readLine()) != null) {
                response.add(line);
            }
            reader.close();
            httpConn.disconnect();
        } else {
            throw new IOException("Server returned non-OK status: " + status);
        }
        return response;
    }

边界字符串是这个

   String boundary = "===" + System.currentTimeMillis() + "===";
4

0 回答 0