Android Question Http_Utils2 catch error string

RandomCoder

Well-Known Member
Licensed User
Longtime User
When trying to browse a UPNP server that requires authorisation, I get Job.Success=False and the Job.ErrorMessage is set to "Internal Server Error". However the Log displays the following....
B4X:
<?xml version="1.0"?>

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
  <SOAP-ENV:Body>
    <SOAP-ENV:Fault>
      <faultcode>SOAP-ENV:Client</faultcode>
      <faultstring>UPnPError</faultstring>
      <detail>
        <u:UPnPError xmlns:u="urn:schemas-upnp-org:control-1-0">
          <u:errorCode>801</u:errorCode>
          <u:errorDescription>Access denied</u:errorDescription>
        </u:UPnPError>
      </detail>
    </SOAP-ENV:Fault>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

I do not know where this Log has originated from as I have disabled all calls to Log in my program and yet still it appears. I've tried to use Job.GetString instead of Job.ErrorMessage but that faults because the the string is Null when Job.Success=False.

I would very much like to access the information in this Logged message as it tells the user that they do not have the necessary access rights to view the UPNP device. I'm guessing that I need to use the reflection library? Please can someone advise on how to proceed?

Thanks,
RandomCoder
 

RandomCoder

Well-Known Member
Licensed User
Longtime User
The server response is currently not included in the ErrorMessage property. It will be added in the future.
Firstly, sorry for reviving an old thread
I was just wondering if with the B4A 3.82 update it is now possible to catch an 801 error code to determine if access has been denied on a browse request?

If not then please can someone expand on what is required to add it myself...
You can add it yourself by modifying HttpUtils2Service code. You will need to remove the library and use the two modules (HttpJob and HttpUtils2Service) instead.
I'm currently using HTTP (v1.36) and HttpUtils2 (v2.01) libraries to identify and browse UPNP media devices on my network.

Attached is my project which is reaching a point where I'm no longer embarrassed to share it , it's still a work in progress and will only browse UPNP media devices that require no authorisation and currently only plays video files, but music and images are easy to add (I've just not done it yet ).

Whilst I'm on the subject of authorisation, does anyone know how to do this within the UPNP standard? I'm currently sending the following browse request...
B4X:
Private Sub BrowseServer(objectID As String, metaData As Boolean)
    Debug.debugLog("##### SEND BROWSE REQUEST #####") 'DEBUG
    ' Set browseFlag to either BrowseMetadata or BrowseDirectChildren
    Dim browseFlag As String
    If metaData = True Then
        browseFlag = "BrowseMetadata"
    Else
        browseFlag = "BrowseDirectChildren"
    End If
  
    browseID = objectID
    ' Create SOAP XML message
    Dim xmlMsg As String
    xmlMsg = "<?xml version='1.0' encoding='utf-8'?>" & _
            "<s:Envelope xmlns:s='http://schemas.xmlsoap.org/soap/envelope/' s:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'>" & _
                "<s:Body>" & _
                    "<u:Browse xmlns:u='" & browseServiceType & "'>" & _
                        "<ObjectID>" & browseID & "</ObjectID>" & _
                        "<BrowseFlag>" & browseFlag & "</BrowseFlag>" & _
                        "<Filter>" & browseFilter & "</Filter>" & _
                        "<StartingIndex>" & browseStartingIndex & "</StartingIndex>" & _
                        "<RequestedCount>" & browseRequestedCount & "</RequestedCount>" & _
                        "<SortCriteria>" & browseSortCriteria & "</SortCriteria>" & _
                    "</u:Browse>" & _
                "</s:Body>" & _
              "</s:Envelope>"
    xmlMsg = xmlMsg.Replace("'", Chr(34))
    Debug.debugLog(xmlMsg) 'DEBUG

    ' Initialise HTTP job
    Dim httpReq As HttpJob
    httpReq.Initialize("Browse",Me)
    httpReq.PostString(browseURL, xmlMsg)
    httpReq.GetRequest.SetContentType("text/xml; charset=" & Chr(34) & "utf-8" & Chr(34))
    httpReq.GetRequest.SetHeader("SOAPAction",Chr(34) & browseServiceType & "#Browse" & Chr(34))
    httpReq.GetRequest.Timeout = 20000
    If browseReset = True Then
        ' Store the objectID being browsed
        Main.browseLog.Add(objectID)
    End If
End Sub
But if I remember correctly I don't think that it can be sent within this request. It's a while ago since I read the docs but seem to think I have to send a authorisation request and be accepted before attempting to browse?

Thanks,
RandomCoder

PS. When I'm eventually finished I plan to share the code here in the Forum along with a brief explanation of the sequence. I hope you like the look of it so far!
 

Attachments

  • UPNP Media Browser.zip
    236.5 KB · Views: 184
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…