Solved

String or STring Array?

Posted on 2013-06-24
9
411 Views
Last Modified: 2013-06-24
I am doing an HTTP Request and

This code below outputs the StreamResponse in a StreamReader

In a Debug.WriteLile it looks like regular XML

So...
Is outputdata a string or an array?

Dim outputData As New [String](readBuff, 0, count)

THis is what outputs in a Debug.WriteLine
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<org.m5.api.v1.Response xmlns:m5="http://www.m5net.com/org/m5/data/v2/cti" xmlns:csta="http://www.ecma-international.org/standards/ecma-323/csta/ed5">
    <ErrorCount>0</ErrorCount>
    <Id>1</Id>
</org.m5.api.v1.Response>
0
Comment
Question by:lrbrister
  • 4
  • 4
9 Comments
 
LVL 42

Expert Comment

by:sedgwick
ID: 39271456
can u post the whole code please?
btw, if u use ReadToEnd() of the StreamReader, u gonna get the whole xml as a string.
for example:
Dim response As WebResponse = webRequest.GetResponse()
Dim responseStream As Stream = response.GetResponseStream()
Dim responseReader As New StreamReader(responseStream)
Dim responseString As String = responseReader.ReadToEnd()

Open in new window

0
 

Author Comment

by:lrbrister
ID: 39271497
Sedgwick

here you go
The part in question is
Dim outputData As New [String](readBuff, 0, count)



Dim streamResponse As Stream = myHttpWebResponse.GetResponseStream()
 While streamResponse.CanRead
	Dim streamRead As New StreamReader(streamResponse)
 	Dim readBuff(2560) As [Char]
	Dim count As Integer = streamRead.Read(readBuff, 0, 2560)
	Dim line As String = ""
	Debug.WriteLine(ControlChars.Cr + "Characters Returned " + CStr(count))
	If count = 0 Then
		GoTo Resend
	Else
		Dim outputData As New [String](readBuff, 0, count)
		Debug.WriteLine(ControlChars.Cr + "The contents of the returned data are :  ")
 		Debug.WriteLine(ControlChars.Cr + outputData + vbCrLf)
                 
	End If
 End While

Open in new window

0
 
LVL 42

Expert Comment

by:sedgwick
ID: 39271531
try this:
Dim streamResponse As Stream = myHttpWebResponse.GetResponseStream()
Dim responseReader As New StreamReader(streamResponse)
Dim responseString As String = responseReader.ReadToEnd()
Debug.WriteLine(ControlChars.Cr + "The contents of the returned data are :  ")
Debug.WriteLine(ControlChars.Cr + responseString + vbCrLf)

Open in new window

0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 39271557
>Is outputdata a string or an array?

You are creating a new instance of string from a byte array so its a string.
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

Author Comment

by:lrbrister
ID: 39271569
sedgewick,
  Huh?

My code works.
I just want to know if that's an array?
0
 
LVL 42

Accepted Solution

by:
sedgwick earned 500 total points
ID: 39271594
i know it works, just saying u dont need to read chunks from the response u can read to the end of the stream.

for your question, outputData  is string not an array,
0
 

Author Comment

by:lrbrister
ID: 39271616
sedgeweck

I'm getting it back in chunks from the ResponseSTream
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 39271674
ok, didn't know that.
hope i was helpful anyway.
cheers
0
 

Author Closing Comment

by:lrbrister
ID: 39271698
That's what I wanted. Thanks
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
SQl help with selection 14 44
Problem to picture file 3 42
Check if number is currency 15 29
Form design in vb.net 7 21
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now