Hello to all,
I need help to understand which HTTP objects I must use in B4A to replicate this Java example. I tried with HttpJob, but there is no match.
B4A code:
Thanks in advance for help
I need help to understand which HTTP objects I must use in B4A to replicate this Java example. I tried with HttpJob, but there is no match.
B4X:
HttpPost httppost = new HttpPost(address); // ?
HttpParams httpParameters = new BasicHttpParams(); // ?
// Set the timeout in milliseconds until a connection is established.
// The default value is zero, that means the timeout is not used.
int timeoutConnection = 3000;
HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection);
// Set the default socket timeout (SO_TIMEOUT)
// in milliseconds which is the timeout for waiting for data.
int timeoutSocket = 5000;
HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);
HttpClient httpclient = new DefaultHttpClient(httpParameters); // ?
// Create print document(String)
String req = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">" +
"<s:Body>" +
// data
"<printerFiscalReceipt>" +
"<beginFiscalReceipt operator=\"10\" />" +
// list
list +
// end list
"<printRecTotal operator=\"10\" description=\"" + "CONTANTE" /*metodo_pag.ToUpper*/ + "\" payment=\"" + updated_total_amount + "\" paymentType=\"2\" index=\"0\" justification=\"1\" />" +
"<printRecMessage operator=\"10\" messageType=\"3\" index=\"1\" font=\"4\" message=\"Arrivederci e Grazie\" />" +
"<endFiscalReceipt operator=\"10\" />" +
"</printerFiscalReceipt>" +
// end data
"</s:Body>" +
"</s:Envelope>";
StringEntity entity = new StringEntity(req , HTTP.UTF_8);
entity.setContentType("text/xml charset=utf-8");
httppost.setEntity(entity);
HttpResponse response = httpclient.execute(httppost); // ?
// Receive response document
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
// Parse response document(DOM)
Document doc = builder.parse(response.getEntity().getContent());
Element el = (Element)doc.getElementsByTagName("response").item(0);
t_status.setText("PRINTER STATUS\n");
t_status.append("Success: " + el.getAttribute("success") + "\n");
t_status.append("Code: " + el.getAttribute("code") + "\n");
t_status.append("Status: " + el.getAttribute("status"));
B4A code:
B4X:
' pulsante
Sub btnTest_Click
Try
Dim j As HttpJob
j.Initialize("send_data", Me)
j.JobName = "Printer"
j.PostString(link, GetStringPrinter)
Catch
Log(LastException)
End Try
End Sub
Private Sub GetStringPrinter As String
Dim aMessage As StringBuilder
aMessage.Initialize
aMessage.Append("String req = '<?xml version=\1.0\encoding=\utf-8\?>'")
aMessage.Append("<s:Envelope xmlns:s=\http://schemas.xmlsoap.org/soap/envelope/\>")
aMessage.Append("<s:Body>")
aMessage.Append("<printerFiscalReceipt>")
aMessage.Append("<beginFiscalReceipt operator=\10\ />")
' data
aMessage.Append("</printerFiscalReceipt>")
aMessage.Append("</s:Body>")
aMessage.Append("</s:Envelope>")
Return aMessage.ToString
end sub
Thanks in advance for help