Down here is one request I want to create with JAVA. But in the first part I want to put XML, not fields or text but XML and in the second - my file which I want to upload. Also every part of my request should have different content type and content disposition.
So How to set different HTTP headers for the different parts like in the request down?
Additional question is: could you explain me what exactly is Content-Disposition and when it is used ?
--boundary-string
Content-Disposition: name="request_payload"
Content-Type: text/xml
<tsRequest>
<datasource name="datasource-name" >
<connectionCredentials name="connection-username" password="connection-password"
embed="embed-flag" />
<project id="project-id" />
</datasource>
</tsRequest>
--boundary-string
Content-Disposition: name="tableau_datasource"; filename="datasource-file-name"
Content-Type: application/octet-stream
content-of-datasource-file
--boundary-string--
I think I saw something but I dont know how to put the my content-disposition in the parts. Here is my code:
HttpClient client = HttpClientBuilder.create().build();
File file = new File("D:/qwe.txt");
HttpPost post = new HttpPost("https://test.com/datasources");
post.setHeader("X-Tableau-Auth", "RfVJIasdsadrW");
StringBody stringBody1 = new StringBody("The XML body is here!", ContentType.APPLICATION_XML);
FileBody fileBody = new FileBody(file, ContentType.APPLICATION_OCTET_STREAM);
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
builder.addPart("text1", stringBody1);
builder.addPart("upfile", fileBody);
HttpEntity entity = builder.build();
post.setEntity(entity);
HttpResponse response = client.execute(post);
System.out.println(response);
How to put here Content-Disposition: name="tableau_datasource"; filename="datasource-file-name"?