2012-07-02 4 views
1

Java Apache HttpClient를 사용하여 다중 테스트 POST 요청을 보내서 일부 테스트 데이터를 BigQuery 테이블로 가져 오려고하지만 HTTP 400 오류 메시지가 계속 나타납니다. "잘못된 업로드 요청 ". BigQuery 튜토리얼을 충분히 따라 가면서 필요한 것을 재현 할 수있을 것이라고 확신하지만 작동하지 않습니다. 누군가이 요청을 살펴보고 무엇인가 잘못되었는지 살펴볼 수 있습니까? POST에서 "잘못된 업로드 요청"

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 ("Content-Type을"...) (변경하는 경우 "내용 - 형식 :".. .), 오류가 "media type 'text/plain'으로 변경되지 않습니다. 유효한 미디어 유형 : [application/octet-stream]".

+0

node.js를 사용하여 멀티 파트 게시를 수행하는 동안 동일한 문제가 발생합니다. 문제가 무엇인지 알았 니? – Gus

+0

@Gus : 아뇨, 안됐지만 다른 프로젝트로 옮겼습니다. 더 이상이 문제를 추구하지 않습니다. 나는 당신이 찾았거나 해결책을 찾았 으면 좋겠다. –

답변

0

Content-Type 헤더 다음에 줄 바꿈이 추가로 있어야합니다.

관련 문제