Note that there are some explanatory texts on larger screens.

plurals
  1. POHTTP Post request on BlackBerry
    primarykey
    data
    text
    <p>I am trying to send a json string , from my BlackBerry OS &lt; 7.X application to my Server. I am trying to use an HTTP Post request. What i have done so far is :</p> <pre><code>String httpURL = "http://ip_of_my_server/phpServer/receiver2.php/" + jsonString; try { HttpConnection httpConn; httpConn = (HttpConnection) Connector.open(httpURL + getConnectionString()); httpConn.setRequestMethod(HttpConnection.POST); httpConn.setRequestProperty("Content-Type", "application/json; charset=utf-8"); DataOutputStream _outStream = new DataOutputStream(httpConn.openDataOutputStream()); byte[] request_body = httpURL.getBytes(); for (int i = 0; i &lt; request_body.length; i++) { _outStream.writeByte(request_body[i]); } DataInputStream _inputStream = new DataInputStream(httpConn.openInputStream()); StringBuffer _responseMessage = new StringBuffer(); int ch; while ((ch = _inputStream.read()) != -1) { _responseMessage.append((char) ch); } String res = (_responseMessage.toString()); String response = res.trim(); System.out.println("!!!!!!!!!!!!!! Response is: " + response); httpConn.close(); } catch (Exception e) { Dialog.alert("Error - " + e.toString()); } </code></pre> <p>The code works in a way that i dont fully understand. The author of the above code suggested to use as an <code>httpURL</code> the URL of the server + my json string. The final result is that on my server instead of arriving the json string , is arriving a string like that :</p> <pre><code>http://ip_of_my_server/phpServer/receiver2.php/ + jsonString </code></pre> <p>I am not familiar with java. I have previously done this for WP7 and iOS and in the <code>httpUrl</code> i put my servers URL and then with a command i was <em>"appending"</em> my json string to the http request and everything worked as expected.</p> <p>How can i append the json string to the above HttpRequest , instead of adding it to the URL so that in the server arrives the JSON String only?</p> <h2>EDIT (providing the rest of the code that was used)</h2> <hr> <pre><code>//used to specify connection type ( wifi - 3g - etc ) public static String getConnectionString() { String connectionString = null; // Wifi is the preferred transmission method if (WLANInfo.getWLANState() == WLANInfo.WLAN_STATE_CONNECTED) { connectionString = ";interface=wifi"; } // Is the carrier network the only way to connect? else if ((CoverageInfo.getCoverageStatus() &amp; CoverageInfo.COVERAGE_DIRECT) == CoverageInfo.COVERAGE_DIRECT) { String carrierUid = getCarrierBIBSUid(); if (carrierUid == null) { // Has carrier coverage, but not BIBS. So use the carrier's TCP network connectionString = ";deviceside=true"; } else { // otherwise, use the Uid to construct a valid carrier BIBS request connectionString = ";deviceside=false;connectionUID="+carrierUid + ";ConnectionType=mds-public"; } } // Check for an MDS connection instead (BlackBerry Enterprise Server) else if ((CoverageInfo.getCoverageStatus() &amp; CoverageInfo.COVERAGE_MDS) == CoverageInfo.COVERAGE_MDS) { connectionString = ";deviceside=false"; } // If there is no connection available abort to avoid hassling the user unnecessarily else if (CoverageInfo.getCoverageStatus() == CoverageInfo.COVERAGE_NONE) { connectionString = "none"; } // In theory, all bases are covered by now so this shouldn't be reachable.But hey, just in case ... else { connectionString = ";deviceside=true"; } System.out.println("!!!!!!!!!!!!!! Connection type is: " + connectionString); return connectionString; } /** * Looks through the phone's service book for a carrier provided BIBS * network * * @return The uid used to connect to that network. */ private synchronized static String getCarrierBIBSUid() { ServiceRecord[] records = ServiceBook.getSB().getRecords(); int currentRecord; for (currentRecord = 0; currentRecord &lt; records.length; currentRecord++) { if (records[currentRecord].getCid().toLowerCase().equals("ippp")) { if (records[currentRecord].getName().toLowerCase() .indexOf("bibs") &gt;= 0) { return records[currentRecord].getUid(); } } } return null; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload