Click here to Skip to main content
15,886,823 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi there, I'm consuming a remote WebService, but i'm unable to extract the jpg file containted in the ResponseBody. I fact, I do save a file, but how can i remove the Mime headers etc, so i can view the image??
Here's my code:

What I have tried:

VB
Sub GetImg(ByVal strUrl As String, ByVal XmlBody As String)
Dim objDom As Object
Dim objXmlHttp As Object
Dim strRet As String
Dim aRes() As Byte, fn As Integer
    
    ' Create objects to DOMDocument and XMLHTTP
    Set objDom = CreateObject("MSXML2.DOMDocument")
    Set objXmlHttp = CreateObject("MSXML2.XMLHTTP")
    
    ' Load XML
    objDom.async = False
    objDom.loadXML XmlBody

    ' Open the webservice
    objXmlHttp.Open "POST", strUrl, False
    
    ' Create headings
    objXmlHttp.setRequestHeader "Content-Type", "image/jpeg"
    objXmlHttp.setRequestHeader "Content-Length", Len(XmlBody)
    
    ' Send XML command
    objXmlHttp.send objDom.xml

    ' Get all response text from webservice
    strRet = objXmlHttp.responseText

    ' Get image
    aRes = objXmlHttp.responseBody
    fn = FreeFile
    Open "a.jpg" For Binary As fn
    Put fn, , aRes
    Close fn

    ' Close objects
    Set objXmlHttp = Nothing
    Set objDom = Nothing 
    
End Sub
Posted
Updated 25-Apr-19 0:18am
v2
Comments
Christian Graus 25-Apr-19 2:58am    
Why on earth are you using VB6?
Nick Katditsik 25-Apr-19 4:45am    
Unfortunately, using vb6 is the only option, since the application is already there.

VB6 is 20 years out of date. If I was forced to use it, I'd write COM components in C++ and call them from VB.

I see you're already using COM objects. So VB6 is actually irrelevant. If the object you're using doesn't have properties with the things you want, you can't do it
 
Share this answer
 
Comments
Nick Katditsik 25-Apr-19 4:40am    
But I do get the file. It's just that I can't remove the headers
Christian Graus 25-Apr-19 18:05pm    
The object doesn't let you? That's what I said
Nick Katditsik 26-Apr-19 2:34am    
it's not that it doesn't let me. It's that I don't know how to do it. I guess that's a better way to extract the jpg. My thought of binary opening the responsebody and remove the header is complicated and slow...
Christian Graus 26-Apr-19 2:35am    
I'm saying you're limited by the interface of the COM object, so it's not a VB6 question
Well, since nobody answers, I binary opened the returned file and removed the headers. But I wonder if there is a better way to extract the actual image from ResponseBody...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900