Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.

public class NetworkTransport

  1. Object
  2. NetworkTransport

ImplementsRpcTransport

The application’s RpcTransport: each request goes through the NetworkManager queue as a ConnectionRequest, waiting with addToQueueAndWait, so a call from the EDT keeps the UI responsive. Headers added with header go on every request, which is how a provider’s API key is passed.

Not shared with the backend, which has com.codename1.backend.WebRpcTransport instead.

Constructors

public NetworkTransport()

Methods

public NetworkTransport header(String name, String value)Adds a header sent with every request, for instance an API key.
public NetworkTransport timeout(int millis)The request timeout in milliseconds; 30 seconds by default.
public String send(String method, String url, String contentType, String body) throws IOExceptionSends one request and answers the response body.

Inherited methods

Constructor details

NetworkTransport

public NetworkTransport()

Method details

header

public NetworkTransport header(String name, String value)
Adds a header sent with every request, for instance an API key.

timeout

public NetworkTransport timeout(int millis)
The request timeout in milliseconds; 30 seconds by default.

send

public String send(String method, String url, String contentType, String body) throws IOException
Sends one request and answers the response body.

Parameters

method String
GET or POST
url String
the full URL
contentType String
the body’s media type, or null for a request without one
body String
the body, or null

Throws

RpcException
for a status outside 2xx, with the status and the body the server sent
IOException
when the request could not be made at all