vb.net - Get a string from a data stream -
i accessing api through .net 3.5 application, , far code looks so:
dim strlink string = "http://www.google.co.uk" dim request webrequest = system.net.webrequest.create("http://random-web-api/controller/id") dim response webresponse = request.getresponse() if ctype(response,httpwebresponse).statuscode = httpstatuscode.ok dim datastream stream = response.getresponsestream() ' how string stream? response.close() end if i able call api, , ok status, don't know how convert responsestream string in vb?
any appreciated.
most easy way think of:
'convert stream string dim reader new streamreader(response.getresponsestream()) dim streamtext string = reader.readtoend() note: work ascii encoding.
edit, add following method application, 1 allows encoding parameter.
private shared function memorystreamtostring(ms memorystream, enc encoding) string return convert.tobase64string(enc.getstring(ms.getbuffer(), 0, cint(ms.length))) end function above function should called like:
dim streamtext string = memorystreamtostring(response.getresponsestream(), system.encoding.encodingtypehere) go here more information encoding msdn
Comments
Post a Comment