Search code examples
c#asp.netstreamhttpwebrequesthttpwebresponse

How To Parse Multipart HttpWebResponse


I'm completely lost on how to parse this multipart httpresponse. This is the format that I receive:

MIME-Version: 1.0
RETS-Version: RETS/1.8
RETS-Server: Interealty-RETS/1.5.247.0
Transfer-Encoding: chunked
Cache-Control: private,private, max-age=0
Date: Sun, 25 Sep 2011 00:45:51 GMT
Set-Cookie: ASP.NET_SessionId=jt11w155vitdtlnwt2p3l345; path=/; HttpOnly,RETS-Session-ID=jt11w155vitdtlnwt2p3l345; path=/
Server: Microsoft-IIS/6.0
X-AspNet-Version: 2.0.50727
Content-Type: multipart/parallel; boundary=yz2C9C5D87FD6148a3986510BCACF917A82C9C5D87FD6148a3986510BCACF917A8ZY
--simple boundary
Content-Type: image/jpeg
Content-ID: 123456
Object-ID: 1
<binary data>
--simple boundary
Content-Type: image/jpeg
Content-ID: 123457
Object-ID: 1
<binary data>

How can I isolate the different parts of the response? This is returning a bunch of images. What I need to do is convert the binary data into the image (which i can do) and save it to the disk in the format Content-ID + "-" + Object-ID + ".jpg". I know how to convert the bytes into the image, i just don't know how to isolate the bytes so i can convert it. Any help and example code would be much appreciated!


Solution

  • I ended up using a library to parse the RETS (Real Estate Transaction Standard) responses. The library I used was called librets.