Hi
I am trying to attach a text document to soap request. Based on some of the online responses, I was able to put the following code together but unfortunately this doesn’t work and throws the following
error.
"unable to find valid certification path to requested target "
I can run my other requests where I don’t need to build the request like this, so what is it in this code that cannot read the certification defined under settings?
Thanks, any help will be appreciated
OkHttpClient client = new OkHttpClient().newBuilder().build();
String filePath = RunConfiguration.getProjectDir() + "/MyFile.txt"
File file = new File(filePath);
//Form request body that will be a multipart
RequestBody requestBody = new MultipartBody.Builder().setType(MultipartBody.FORM)
.addFormDataPart('UserId', "AAA")
.addFormDataPart("file", file.getName(),
RequestBody.create(MediaType.parse("application/text"), file))
.build();
//Form the actual request adding necessary headers
Request request = new Request.Builder()
.url(url)
.post(requestBody)
.addHeader("Authorization", "Basic adfkskskdfkshfkjhsdafj")
.addHeader("Content-Type", "charset=UTF-8;")
.addHeader("Accept", "*/*")
.build();
Response response = null;
try {
response = client.newCall(request).execute();
println("************ IMPORT TEST EXECUTION RESULTS RAW RESPONSE ************");
println("Response status: " + response);
println("********************************************************************");
if (response.isSuccessful()){
String responseBody = response.body().string();
println("************ IMPORT TEST EXECUTION RESULTS RESPONSE BODY ************");
println(responseBody);
println("*********************************************************************");
} else {
throw new IOException("Unexpected HTTP code " + response);
}
} catch (IOException e) {
e.printStackTrace();
}