[Question]Android send json data to DotNet WCF Api

eric010101

Member
Licensed User
Longtime User
I send json data to DotNet WCF Api,
but it has some Error : Bad Request 400

code:
JSON="[{"authkey":"kesy","id":"00AABBCC"}]"
req.InitializePost2(url,JSON.GetBytes("UTF8"))
req.SetContentType("application/json")
hc.Execute(req,1)

when i asked the WCF Api company
they sad i should Replace " to \" in the JSON format
like it:[{\"authkey\":\"kesy\",\"id\":\"00AABBCC\"}]

but when i do it,it`s not work
always get the same Error: Bad Request 400

what can i do?:sign0085:
 

vincentehsu

Member
Licensed User
Longtime User
dear eric:
did u find answer for this issue? could u please share the projct with me? there is no other actually sample code for wcf via json
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
B4X:
Sub CallWebservice
  Dim URL As String  = "http://api.geonames.org/citiesJSON"
  Log(URL)
  
    Dim job As HttpJob
    job.Initialize("test",Me)
    '?formatted=true&north=44.1&south=-9.9&east=-22.4&west=55.2
    job.download2(URL, Array As String( _
        "username", "putyourusernamehere", _
        "north", 44.1, _
        "south", 9.9, _
        "east", 22.4, _
        "west", 55.2, _
        "type", "json", _
        "lang", "de", _
        "style", "full", _
        "maxRows", 10, _
        "formatted", True _
    ))
    job.GetRequest.Timeout = 6000000
End Sub

Sub JobDone (Job As HttpJob)
   Log("JobName = " & Job.JobName & ", Success = " & Job.Success)
   If Job.Success = True Then
      Select Job.JobName
         Case "test"
            'print the result to the logs
            Log(Job.GetString)
                        Dim parser As JSONParser
                        parser.Initialize(Job.GetString)
                        Dim root As Map = parser.NextObject
                        Dim geonames As List = root.Get("geonames")
                        For Each colgeonames As Map In geonames
                            Dim fcodeName As String = colgeonames.Get("fcodeName")
                            Dim toponymName As String = colgeonames.Get("toponymName")
                            Dim countrycode As String = colgeonames.Get("countrycode")
                            Log("countrycode="&countrycode)
                            Dim fcl As String = colgeonames.Get("fcl")
                            Log("fcl="&fcl)
                            Dim fclName As String = colgeonames.Get("fclName")
                            Log("fclname="&fclName)
                            Dim name As String = colgeonames.Get("name")
                            Log("name="&name)
                            Dim wikipedia As String = colgeonames.Get("wikipedia")
                            Dim lng As Double = colgeonames.Get("lng")
                            Dim fcode As String = colgeonames.Get("fcode")
                            Dim geonameId As Int = colgeonames.Get("geonameId")
                            Dim lat As Double = colgeonames.Get("lat")
                            Dim population As Int = colgeonames.Get("population")
                            Log("population="&population)
                            Log("======================================================")
                        Next
            End Select
   Else
      Log("Error: " & Job.ErrorMessage)
      ToastMessageShow("Error: " & Job.ErrorMessage, True)
   End If
   Job.Release
End Sub


 

Attachments

  • webservicesjson.zip
    6.9 KB · Views: 220
Upvote 0