Hi,
I am using the following code to connect to the server using the iOS port on iPhone:
ConnectionRequest actReq = new ConnectionRequest() {
protected void buildRequestBody(OutputStream os) throws IOException {
super.buildRequestBody(os);
// Write the JSON object as UTF string
DataOutputStream dos = new DataOutputStream(os);
dos.writeUTF(requestObj.toString());
dos.flush();
}
};
// Allow duplicate network connection request, as we will always
// send the request to the same URL however with different form data
actReq.setDuplicateSupported(true);
actReq.setUrl(getServerURL());
actReq.setSilentRetryCount(1); // Silently retry one more time before giving error
actReq.setPost(true);
actReq.setContentType("application/json");
actReq.addRequestHeader("Accept", "application/json");
actReq.addRequestHeader("CLIENT_API_VERSION","1.0");
NetworkManager.getInstance().addToQueue(actReq);
And on the server I use the following code to read the request(where req is the HttpServletRequest):
DataInputStream in = new DataInputStream(req.getInputStream());
HttpSession session = req.getSession(true);
String versionString = req.getHeader("CLIENT_API_VERSION");
String inStr = in.readUTF();
This code works in codename1 simulator and correctly connects to the server and gets the response back.
However when I use the same code, for iOS port, on actual iPhone device, it connects to the server, but then on the server side it gives the following error:
java.io.EOFException
at java.io.DataInputStream.readUnsignedShort(DataInputStream.java:323)
at java.io.DataInputStream.readUTF(DataInputStream.java:572)
at java.io.DataInputStream.readUTF(DataInputStream.java:547)
Also the versionString(CLIENT_API_VERSION) request header is coming out to be null when request is from actual device.
Has anyone encountered the similar issue or connected to server using the iOS port? Please let me know, if anyone has any idea what could be the issue here.
Thanks,
Nirmal