Google bigquery &引用;上传请求无效“;邮寄

Google bigquery &引用;上传请求无效“;邮寄,google-bigquery,Google Bigquery,我试图使用JavaApacheHttpClient发送一个多部分POST请求,以将一些测试数据导入到BigQuery表中,但我不断收到HTTP 400错误消息“上传请求无效”。我很确定我很好地遵循了BigQuery教程,能够重现所需的内容,但它不起作用。有人能看看这个请求,看看是否有什么问题吗 String rawInput = "--xxx\n"; rawInput += "Content-Type: application/json; charset=UTF-8\n";

我试图使用JavaApacheHttpClient发送一个多部分POST请求,以将一些测试数据导入到BigQuery表中,但我不断收到HTTP 400错误消息“上传请求无效”。我很确定我很好地遵循了BigQuery教程,能够重现所需的内容,但它不起作用。有人能看看这个请求,看看是否有什么问题吗

    String rawInput = "--xxx\n";
    rawInput += "Content-Type: application/json; charset=UTF-8\n";
    rawInput += "{\n";
    rawInput += "'configuration': {\n"; 
    rawInput += "'load': {\n";
    rawInput += "'schema': {\n";
    rawInput += "'fields': [\n";
    rawInput += "{'name':'field1', 'type':'STRING'},\n";
    rawInput += "{'name':'field2', 'type':'STRING'},\n";
    rawInput += "{'name':'field3', 'type':'STRING'},\n";
    rawInput += "{'name':'field4', 'type':'STRING'},\n";
    rawInput += "]\n";
    rawInput += "},\n";
    rawInput += "'destinationTable': {\n";
    rawInput += "'projectId': 'xxxxxxxxxxx [redacted]',\n";
    rawInput += "'datasetId': 'test',\n";
    rawInput += "'tableId': 'test'\n";
    rawInput += "}\n";
    rawInput += "createDisposition = CREATE_IF_NEEDED\n";           
    rawInput += "}\n";
    rawInput += "}\n";
    rawInput += "}\n";
    rawInput += "--xxx\n";
    rawInput += "Content-Type: application/octet-stream\n";
    rawInput += "\n";
    rawInput += "1,1234,11111111,1\n";
    rawInput += "2,5678,11111111,1\n";
    rawInput += "3,9101,11111111,1\n";
    rawInput += "4,6543,11111111,1\n";
    rawInput += "--xxx--";
然后按如下方式执行请求:

    postRequest.addHeader("Content-Type", "multipart/related; boundary=xxx;");
    postRequest.addHeader("Authorization", "OAuth " + credential.getAccessToken());
    StringEntity input = new StringEntity(rawInput);
    postRequest.setEntity(input);
    HttpResponse response = httpClient.execute(postRequest);

此外,如果我将addHeader(“内容类型”…)更改为addHeader(“内容类型:”…),则错误将更改为“媒体类型‘text/plain’。有效的媒体类型:[应用程序/八位字节流]”。

在内容类型头后应该有一个额外的换行符

rawInput += "Content-Type: application/json; charset=UTF-8\n\n";

我在使用node.js进行多部分post时遇到了同样的问题。你发现问题出在哪里了吗?@Gus:不,不幸的是我没有,我已经转到另一个项目,所以我不再讨论这个问题。不过,我希望你找到了解决办法!