Android Question OkHttpUtils2 instead HttpUtils2 in WebService

netsistemas

Active Member
Licensed User
Longtime User
I change the referente to the new library OkHttpUtils2 but when i call a WebService, the jobDone return me a error:
ResponseError. Reason: Unsupported Media Type, Response: El servidor no puede atender la solicitud porque no el tipo de medio no es compatible.

WebService define:
http://([URL='http://www.factunet.net/webservice/service1.asmx?op=SetGPS'](omited by author)[/URL]
or
https://[URL='http://www.factunet.net/webservice/service1.asmx?op=SetGPS'](omited by author)[/URL]

With HttpUtils2 there are not error, but, i think thak a need migrated to last version
the error are captured in Sub JobDone (job As HttpJob)
 
Last edited:

netsistemas

Active Member
Licensed User
Longtime User
Petition to WS:

In Process Glabal:
B4X:
Dim SRaiz As StringBuilder
    SRaiz.Initialize
    SRaiz.Append("<?xml version='1.0' encoding='utf-8'?>")
    SRaiz.Append("<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>")
    SRaiz.Append("  <soap:Body>")
   
    Dim SFinal As StringBuilder
    SFinal.Initialize
    SFinal.Append("  </soap:Body>")
    SFinal.Append("</soap:Envelope>")

In SUB:

B4X:
S.Initialize
            ' Dim Sql As String = "Insert into UbicacionGPS(Persona, Latitud, Longitud, InstanteTerminal, Estado) Values ('"
                 
            S.Append(SRaiz.ToString)
            S.Append("      <SetGPS xmlns='http://tempuri.org/'>")
            S.Append("      <Empresa>" & Empresa & "</Empresa>")
            S.Append("      <Terminal>xxxxxxx</Terminal>")
            S.Append("      <Usuario>" & Terminal & "</Usuario>")
            S.Append("      <Latitud>" & modVarios.V_Config.UltimaLat &  "</Latitud>")
            S.Append("      <Longitud>" & modVarios.V_Config.Ultimalon & "</Longitud>")
            S.Append("      <Estado>" & Estado & "</Estado>")
            S.Append("      <Notas>" & Notas  & "</Notas>")
            S.Append("      </SetGPS>")
            S.Append(SFinal.ToString)
            RequestSoapXML = S.ToString
            'Log(S.ToString )
           
            job2.Initialize(job2,Me)'ignore
            job2.PostString(url,RequestSoapXML)

            'job2.GetRequest.SetContentType("application/json")
           
            'job2.GetRequest.SetHeader("Content-Type", "text/xml; charset=utf-8")
            job2.GetRequest.SetHeader("Content-Type", "Application/soap+xml; charset=utf-8")
            Log("Solicitud a WS Enviada")


In JOBDONE and TRY ERROR:

B4X:
Sub JobDone (job As HttpJob)
    'Msgbox("JobName = " & job.JobName & ", Success = " & job.Success,"")
    Dim txt As String
    Dim ErrorProducido As Boolean
    Try
     

        'StartService( HttpUtils2Service)
        ErrorProducido = False
        If job.Success = True Then

            txt = job.GetString

         


        Else

            'Msgbox("Error al terminar un trabajo en el WEBSERVICE" & CRLF & job.ErrorMessage ,"")
            ToastMessageShow("Error: " & job.ErrorMessage, True)
            ErrorProducido  = True

                 
        End If
     
        job.Release
        If ErrorProducido = False Then

            'SE extrae los sacado del SW y se carga al PARSE. Éste se ejecutará al finalizar: ver Parser_EndElement
            Dim Istream As InputStream
            Istream =  StringToInputStream(txt )
            Log(txt)
            parser.Parse(Istream , "Parser")
            Istream.Close

     
        End If
    Catch
        Log(LastException)
    End Try

End Sub
 
Last edited:
Upvote 0

netsistemas

Active Member
Licensed User
Longtime User
PERFECT!!!!
Thanks.

I was close...
'New code:
job2.GetRequest.SetContentType("text/xml; charset=utf-8")

'deprecated code (no required):
'job2.GetRequest.SetHeader("Content-Type", "text/xml; charset=utf-8")
 
Upvote 0
Top