Created
February 20, 2013 04:19
-
-
Save jonathanhoskin/4992853 to your computer and use it in GitHub Desktop.
vWorkApp API Compression .Net Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Imports System.IO.Compression 'required import to reference the gzipstream in .net | |
Private Function getWorkerList(ByRef xnodRoot As XmlNode) As Boolean | |
Dim strURL = "http://api.vworkapp.com/2.0/workers.xml?api_key=" & APIKEY | |
' WriteLog("URL TO POST: " + strPostURL) | |
Dim answer = False | |
Dim requestStream As Stream = Nothing | |
Dim fileStream As FileStream = Nothing | |
Dim uploadResponse As Net.HttpWebResponse = Nothing | |
Try | |
Dim downloadRequest As Net.HttpWebRequest = CType(Net.HttpWebRequest.Create(strURL), Net.HttpWebRequest) | |
downloadRequest.Method = Net.WebRequestMethods.Http.Get | |
downloadRequest.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip,deflate") | |
uploadResponse = downloadRequest.GetResponse() | |
Dim doc As XmlDocument = New XmlDocument() | |
If (uploadResponse.ContentEncoding.ToLower().Contains("gzip")) Then | |
doc.Load(New GZipStream(uploadResponse.GetResponseStream(), CompressionMode.Decompress)) | |
Else | |
doc.Load(uploadResponse.GetResponseStream()) | |
End If | |
' MsgBox(doc.OuterXml()) 'shows the xml file in full | |
' MsgBox(doc.Attributes.Count) | |
xnodRoot = doc.DocumentElement | |
answer = True | |
Catch ex As UriFormatException | |
MsgBox("b " & ex.Message) | |
Catch ex As IOException | |
MsgBox("c " & ex.Message) | |
Catch ex As Net.WebException | |
MsgBox("d " & ex.Message) | |
Catch ex As Exception | |
MsgBox("getjoblist error: " & ex.ToString) | |
Finally | |
If uploadResponse IsNot Nothing Then | |
uploadResponse.Close() | |
End If | |
If requestStream IsNot Nothing Then | |
requestStream.Close() | |
End If | |
End Try | |
Return answer | |
End Function |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment