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

**URL:** <https://forum.katalon.com/t/java-net-unknownhostexception-when-test-and-verify-post-uploadedfile-form-data/34966>\
**Category:** API Testing\
**Tags:** api-testing, katalon-studio\
**Created:** [October 21, 2019, 1:59am UTC](https://forum.katalon.com/t/java-net-unknownhostexception-when-test-and-verify-post-uploadedfile-form-data/34966 "2019-10-21T01:59:02Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gan\_Jyi\_Yng](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/gan_jyi_yng/32/16104_2.png) [@Gan\_Jyi\_Yng](https://forum.katalon.com/u/Gan_Jyi_Yng)\
**Post date:** [October 21, 2019, 1:59am UTC](https://forum.katalon.com/t/java-net-unknownhostexception-when-test-and-verify-post-uploadedfile-form-data/34966/1 "2019-10-21T01:59:02Z")

</div>

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

 ![katalon%20upd](https://europe1.discourse-cdn.com/katalon/original/2X/7/72b85a38b4200712496c5efaa0434ca1c38620e6.png)

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

---

<div class="post-metadata">

**Author:** ![huynguyen](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/huynguyen/32/552_2.png) [@huynguyen](https://forum.katalon.com/u/huynguyen)\
**Post date:** [October 21, 2019, 5:38pm UTC](https://forum.katalon.com/t/java-net-unknownhostexception-when-test-and-verify-post-uploadedfile-form-data/34966/2 "2019-10-21T17:38:58Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Gan\_Jyi\_Yng](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/gan_jyi_yng/32/16104_2.png) [@Gan\_Jyi\_Yng](https://forum.katalon.com/u/Gan_Jyi_Yng)\
**Post date:** [October 22, 2019, 6:14am UTC](https://forum.katalon.com/t/java-net-unknownhostexception-when-test-and-verify-post-uploadedfile-form-data/34966/3 "2019-10-22T06:14:28Z")

</div>

> [@huynguyen](#):
>
> ur request object file (.rs file) ?

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)

---

<div class="post-metadata">

**Author:** ![huynguyen](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/huynguyen/32/552_2.png) [@huynguyen](https://forum.katalon.com/u/huynguyen)\
**Post date:** [October 22, 2019, 7:01am UTC](https://forum.katalon.com/t/java-net-unknownhostexception-when-test-and-verify-post-uploadedfile-form-data/34966/4 "2019-10-22T07:01:16Z")

</div>

Hi @Gan_Jyi_Yng,  
Please post the whole .rs file as it is, not the content of it 😃. 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.

---

<div class="post-metadata">

**Author:** ![Gan\_Jyi\_Yng](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/gan_jyi_yng/32/16104_2.png) [@Gan\_Jyi\_Yng](https://forum.katalon.com/u/Gan_Jyi_Yng)\
**Post date:** [October 22, 2019, 7:02am UTC](https://forum.katalon.com/t/java-net-unknownhostexception-when-test-and-verify-post-uploadedfile-form-data/34966/5 "2019-10-22T07:02:37Z")

</div>

[ApiDrugUploadPost.zip](https://europe1.discourse-cdn.com/katalon/original/2X/2/2c38624fddd049715212e38ed346307bf9637c7d.zip) (1.1 KB)

---

<div class="post-metadata">

**Author:** ![Gan\_Jyi\_Yng](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/gan_jyi_yng/32/16104_2.png) [@Gan\_Jyi\_Yng](https://forum.katalon.com/u/Gan_Jyi_Yng)\
**Post date:** [October 22, 2019, 7:02am UTC](https://forum.katalon.com/t/java-net-unknownhostexception-when-test-and-verify-post-uploadedfile-form-data/34966/6 "2019-10-22T07:02:51Z")

</div>

attached the file

---

<div class="post-metadata">

**Author:** ![huynguyen](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/huynguyen/32/552_2.png) [@huynguyen](https://forum.katalon.com/u/huynguyen)\
**Post date:** [October 22, 2019, 7:05am UTC](https://forum.katalon.com/t/java-net-unknownhostexception-when-test-and-verify-post-uploadedfile-form-data/34966/7 "2019-10-22T07:05:00Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Gan\_Jyi\_Yng](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/gan_jyi_yng/32/16104_2.png) [@Gan\_Jyi\_Yng](https://forum.katalon.com/u/Gan_Jyi_Yng)\
**Post date:** [October 22, 2019, 8:09am UTC](https://forum.katalon.com/t/java-net-unknownhostexception-when-test-and-verify-post-uploadedfile-form-data/34966/8 "2019-10-22T08:09:47Z")

</div>

> [@huynguyen](#):
>
> 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.

 ![try2](https://europe1.discourse-cdn.com/katalon/original/2X/6/68097502e9fff69deecd502e48251d5674286fae.png)

---

<div class="post-metadata">

**Author:** ![huynguyen](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/huynguyen/32/552_2.png) [@huynguyen](https://forum.katalon.com/u/huynguyen)\
**Post date:** [October 22, 2019, 8:52am UTC](https://forum.katalon.com/t/java-net-unknownhostexception-when-test-and-verify-post-uploadedfile-form-data/34966/9 "2019-10-22T08:52:19Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Gan\_Jyi\_Yng](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/gan_jyi_yng/32/16104_2.png) [@Gan\_Jyi\_Yng](https://forum.katalon.com/u/Gan_Jyi_Yng)\
**Post date:** [October 22, 2019, 9:00am UTC](https://forum.katalon.com/t/java-net-unknownhostexception-when-test-and-verify-post-uploadedfile-form-data/34966/10 "2019-10-22T09:00:50Z")

</div>

{  
“log” : {  
“version” : “1.2”,  
“pages” : [],  
“entries” : [ {  
“startedDateTime” : “2019-10-22T09:00:30.845Z”,  
“request” : {  
“method” : “POST”,  
“url” : “[http://localhost:8015/api/items/drug/upload](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](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” : “”  
}  
}

---

<div class="post-metadata">

**Author:** ![Gan\_Jyi\_Yng](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/gan_jyi_yng/32/16104_2.png) [@Gan\_Jyi\_Yng](https://forum.katalon.com/u/Gan_Jyi_Yng)\
**Post date:** [October 22, 2019, 9:02am UTC](https://forum.katalon.com/t/java-net-unknownhostexception-when-test-and-verify-post-uploadedfile-form-data/34966/11 "2019-10-22T09:02:00Z")

</div>

> [@Gan\_Jyi\_Yng](#):
>
> }, {  
> “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” : “”  
> },

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

---

<div class="post-metadata">

**Author:** ![Gan\_Jyi\_Yng](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/gan_jyi_yng/32/16104_2.png) [@Gan\_Jyi\_Yng](https://forum.katalon.com/u/Gan_Jyi_Yng)\
**Post date:** [October 22, 2019, 9:07am UTC](https://forum.katalon.com/t/java-net-unknownhostexception-when-test-and-verify-post-uploadedfile-form-data/34966/12 "2019-10-22T09:07:21Z")

</div>

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()

---

<div class="post-metadata">

**Author:** ![Gan\_Jyi\_Yng](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/gan_jyi_yng/32/16104_2.png) [@Gan\_Jyi\_Yng](https://forum.katalon.com/u/Gan_Jyi_Yng)\
**Post date:** [October 23, 2019, 1:59am UTC](https://forum.katalon.com/t/java-net-unknownhostexception-when-test-and-verify-post-uploadedfile-form-data/34966/13 "2019-10-23T01:59:45Z")

</div>

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.
