java.net.UnknownHostException when test and verify POST uploadedfile form-data

is katalon supported form-data POST method?
the same file was uploaded successfully by POSTMAN but java error throw when using katalon
HTTP header is content type application/json
HTTP body is form-data , then browse file

response error:
{
“fileError”:{
“unhandled”:“Error can’t handle”
}
}

Hi @Gan_Jyi_Yng,
Can you share your request object file (.rs file) ?
Regards.

here is the rs file

<?xml version="1.0" encoding="UTF-8"?> ApiDrugUploadPost 6930706f-2efc-4d40-a313-9320d2b42577 BASIC false false { "parameters": [ { "name": "uploadedFile", "value": "Data Files\\ImportData.xlsx", "type": "file" } ] } form-data true equals Content-Type Main multipart/form-data true equals Content-Type Main application/json 5.4.1 POST http://${URL}:${Port}/api/upload RESTful GlobalVariable.URL df120fa8-9e2e-4f42-95a5-444bf23c113f false URL GlobalVariable.Port 050ce16a-45f9-4563-8964-25bf837a09f6 false Port import static org.assertj.core.api.Assertions.*

import com.kms.katalon.core.testobject.RequestObject
import com.kms.katalon.core.testobject.ResponseObject
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
import com.kms.katalon.core.webservice.verification.WSResponseManager

import groovy.json.JsonSlurper
import internal.GlobalVariable as GlobalVariable

RequestObject request = WSResponseManager.getInstance().getCurrentRequest()

ResponseObject response = WSResponseManager.getInstance().getCurrentResponse()

WS.verifyResponseStatusCode(response, 201)

assertThat(response.getStatusCode()).isEqualTo(201)

Hi @Gan_Jyi_Yng,
Please post the whole .rs file as it is, not the content of it :smiley:. In the mean time, I notice that your HTTP body is multipart/form-data type but your Content-Type header is application/json, while it should be multipart/form-data also. Please check again.
Regards.

ApiDrugUploadPost.zip (1.1 KB)

attached the file

I notice that your HTTP body is multipart/form-data type but your Content-Type header is application/json, while it should be multipart/form-data also. Please check again.

i tried one content type application/json -> not working
then tried content type multipart/form-data -> not working
then i tried both content type, still not working
what should be the right setup? in POSTMAN, i need content type application/json and it works easily.

Hi @Gan_Jyi_Yng,
Can you share the HAR file? You can find it at the top right corner of the request object view.
Regards.

{
“log” : {
“version” : “1.2”,
“pages” : [ ],
“entries” : [ {
“startedDateTime” : “2019-10-22T09:00:30.845Z”,
“request” : {
“method” : “POST”,
“url” : “http://localhost:8015/api/items/drug/upload”,
“httpVersion” : “”,
“cookies” : [ ],
“headers” : [ {
“name” : “Content-Type”,
“value” : “multipart/form-data”
}, {
“name” : “Content-Type”,
“value” : “application/json”
} ],
“queryString” : [ ],
“postData” : {
“mimeType” : “multipart/form-data”,
“text” : “–qVryeJ75v3BAvsxGsiRTjRHq_kWfVIcF\r\nContent-Disposition: form-data; name=“uploadedFile”\r\nContent-Type: text/plain; charset=ISO-8859-1\r\nContent-Transfer-Encoding: 8bit\r\n\r\nData Files\b-DrugImportData.xlsx\r\n–qVryeJ75v3BAvsxGsiRTjRHq_kWfVIcF–\r\n”,
“comment” : “”
},
“headersSize” : 0,
“bodySize” : 0,
“comment” : “”
},
“response” : {
“status” : 201,
“statusText” : “”,
“httpVersion” : “”,
“cookies” : [ ],
“headers” : [ {
“name” : “Transfer-Encoding”,
“value” : “chunked”
}, {
“name” : null,
“value” : “HTTP/1.1 201 Created”
}, {
“name” : “Server”,
“value” : “Kestrel”
}, {
“name” : “api-supported-versions”,
“value” : “1.0”
}, {
“name” : “Date”,
“value” : “Tue, 22 Oct 2019 09:00:30 GMT”
}, {
“name” : “Location”,
“value” : “http://localhost:8015/api/items/drug/upload
}, {
“name” : “Content-Type”,
“value” : “application/json; charset=utf-8”
} ],
“content” : {
“size” : 48,
“mimeType” : “application/json; charset=utf-8”,
“text” : “{“fileError”:{“unhandled”:“Error can’t handle”}}”,
“comment” : “”
},
“redirectURL” : “”,
“headersSize” : 189,
“bodySize” : 48,
“comment” : “”
},
“cache” : { },
“timings” : {
“comment” : “”,
“connect” : 78,
“blocked” : -1,
“wait” : 0,
“dns” : -1,
“send” : 0,
“receive” : 0,
“ssl” : -1
},
“comment” : “”,
“_katalonRequestInformation” : {
“name” : “1”,
“testObjectId” : “C:\JY\DrugService-18Oct\DrugService\katalon-drug-service\Object Repository\Web Service Request\drug-service\ApiDrugUploadPost.rs”,
“harId” : “f9441938-b860-422f-8e6e-d3722985ef8c”,
“reportFolder” : null
},
“time” : 78
} ],
“comment” : “”
}
}

above the result HAR
noticed a small window prompted java error after i restarted katalon, unable to capture it

maybe Katalon object repo HTTP header has issues.
i actually raised a bug at Katalon Bug section as i noticed the HTTP header is not maintained when changing other section like BODY/ endpoint. sometimes it reset to blank, causing issues if tester not aware the changes, test will failed always, tester have to manually adding back the correct HTTP header.

i have workaround which i bypass object repo, add below codes directly at test cases and call the endpoint. this works perfect.
def requestObject = builder.withRestRequestMethod(‘POST’)
.withRestUrl(‘http://’+GlobalVariable.SiteHostName+":"+GlobalVariable.Port + ‘/api/items/upload’)
.withHttpHeaders([
new TestObjectProperty(‘Content-Type’, ConditionType.EQUALS, ‘multipart/form-data’)])
.withMultipartFormDataBodyContent([
new FormDataBodyParameter(‘uploadedFile’,“Data Files/Data.xlsx” , ‘File’), ])
.build()

i just did below steps and object is working

  1. remove object
  2. add new object
  3. go to http body select form-data then file , http header automatically inserted multi-form content type
  4. test and verify - works
    issue could be the object was copy and duplicate then modify later on, create new object from scratch working good.