# multipartformdata connection

**URL:** <https://techcommunity.softwareag.com/t/multipartformdata-connection/176166>\
**Category:** Forum\
**Tags:** mobile\
**Created:** [May 5, 2014, 9:54am UTC](https://techcommunity.softwareag.com/t/multipartformdata-connection/176166 "2014-05-05T09:54:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ken\_Peersman1](https://avatars.discourse-cdn.com/v4/letter/k/85e7bf/32.png) [@Ken\_Peersman1](https://techcommunity.softwareag.com/u/Ken_Peersman1)\
**Post date:** [May 5, 2014, 9:54am UTC](https://techcommunity.softwareag.com/t/multipartformdata-connection/176166/1 "2014-05-05T09:54:24Z")

</div>

Hi all,

I’m sorry for the many questions, but i really don’t find mutch information about the things I need to do.

The problem I have now is the next one:  
I need to send a JSON file to a server, so far so good.  
With the example of nativeUIJSON I managed to send a JSON tot the server and it works.

But now I need to put this JSON file in a multipartformdata request because this is the format the server need.  
Does anyone have an idee how to change the code below so I can send multipartformdata request …?

Already many thanks.

```auto

public class ServerConnection extends Thread
{
	static HttpConnectionHandler connection;
	static byte server_data [];

	nUIObject object;
	String url;
	int successEvent = nUIConstants.EVT_TRIGGER_HTTP_SUCCESS;

	/**
	 * if this is a GET instead of a POST call, set post_data to null
	 */
	public static void connect(nUIObject object, String url, byte post_data [], int successEvent)
	{
		ServerConnection hc = new ServerConnection();
		hc.object = object;
		hc.url = url;
		hc.successEvent = successEvent;

		connection = HttpConnectionHandler.openHttpConnectionByteArrayData(url, HttpConnectionHandler.Encoding_Default, post_data);

		// wait for the response on a secondary thread
		hc.start();
	}
	// to support single calls that just respond with an HTTP success
	public static void connect(nUIObject object, String url, byte post_data [])
	{
		connect(object, url, post_data, nUIConstants.EVT_TRIGGER_HTTP_SUCCESS);
	}

	public void run()
	{
		// wait for the server to respond (or not)
		do
		{
			try
			{
				Thread.sleep(50);
			}
			catch(Exception e)
			{
			}
		}
		while(!(connection.cancelled));

		// problem?
		if(connection.response_code != javax.microedition.io.HttpConnection.HTTP_OK)
		{
			nUIController.eventListenerQueue(object, nUIConstants.EVT_TRIGGER_HTTP_FAIL);
			return;
		}

		ServerConnection.server_data = connection.response_data;

		// success!
		nUIController.eventListenerQueue(object, successEvent);
	}
}
```

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/techcommunity/original/3X/c/d/cd19967bb605d28a72d77eb83a1cae22f3df2eb8.svg) [@system](https://techcommunity.softwareag.com/u/system)\
**Post date:** [April 2, 2021, 3:31pm UTC](https://techcommunity.softwareag.com/t/multipartformdata-connection/176166/2 "2021-04-02T15:31:01Z")

</div>


