Android Question Http Poststring JSON URL Encoding

Discussion in 'Android Questions' started by lip, Feb 7, 2015.

  1. lip

    lip Active Member Licensed User

    I am able to transfer SQLite records one at a time with HTtP using Posstring with a string like

    My co-developer at the server end is using .net and he reads the Post and inserts/updates a SQL record.

    My problem comes when I try to use JSON ie something like:

    I have used log(myPoststring) immediately before Job1.Poststring(myurl,myPoststring) and I see the JSON object included in the string as above

    However, at the server end we log the received string as:-

    We cannot work out where, how or why the JSON part of the string is being url encoded when the first part of the string is not being encoded.

    I realise that this could be happening at the server end but my web developer is adamant that this is how the string is received.

    Any advice, or ammunition, much appreciated
  2. Erel

    Erel Administrator Staff Member Licensed User

    HttpUtils2 (or HttpClient) doesn't modify the message in any way.

    Have you tried to url-encode the json string with StringUtils?
  3. KMatle

    KMatle Expert Licensed User

    Are you using UTF8 on the server side?
  4. lip

    lip Active Member Licensed User

    I am using the JSonGenerator. Do I need StringUtils tool?

    Sub CloudSyncDevice As Int
    'Record Sync Time
        Dim LastSynced As Long
            LastSynced = Subs.GetParamIntLong(
    Dim DeviceToSyncC As Cursor
            DeviceToSyncC = Main.WiE3SQL.ExecQuery(
    "SELECT DeviceSN, Drawing, PosTop, PosLeft, DeviceType, ApplicationID, ConfigByte, ConfigOptions, MinDaylightLevel FROM Device WHERE DeviceSN > 1000 AND LastEdit > " & LastSynced)
    If DeviceToSyncC.RowCount = 0 Then
    Return 0
    'Create a List of Device Maps
            Dim DeviceList As List
    For i = 0 To DeviceToSyncC.RowCount - 1
                DeviceToSyncC.Position = i
    Dim DeviceRecord As Map
    'Create the JSON Object
            Dim DeviceJSON As JSONGenerator
    If Main.CloudConnected AND Main.CloudEnabled Then
    ToastMessageShow("JSON for " & DeviceToSyncC.RowCount & " Devices Sent to " & "DeviceUpload.aspx",False)
    Dim myTimeStored As Long
                    myTimeStored = 
    'Create String to Post
                Dim myPostString As String
                    myPostString = 
    "PostCode=" & Main.ActivePostcode & _
    "&UserID=1" & _
    "&Collator=" & Main.AndroidID & _
    "&TimeStored=" & myTimeStored & _
    "&DeviceJSON=" & DeviceJSON.ToString
    'Initialise HTTP Job
                Dim Job1 As HttpJob
    'Default timeout is 30 seconds.  Use line below to change it
                    'Job1.GetRequest.Timeout = 30000
    'Post the String inc JSON
                Job1.PostString(Main.HTTPServer & "DeviceUpload.aspx",myPostString)
    End If
    'Get Sync Count before closing cursor
            Dim myDevicesSynced As Int
                myDevicesSynced = DeviceToSyncC.RowCount
    'Close Cursor and Return
    Return myDevicesSynced
    End If
    End Sub
  5. Erel

    Erel Administrator Staff Member Licensed User

    Your code is correct. The problem is probably in the server configuration. HttpJob.PostString doesn't modify the payload.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice