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.
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);
}
}