468,463 Members | 2,026 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,463 developers. It's quick & easy.

no accessible 'GetBytes' can be called with these arguments

les
I'm trying to http post xml data to a remote server and I get this
error:

BC30518: Overload resolution failed because no accessible 'GetBytes'
can be called with these arguments:

Line 20: Dim d As Byte() =
System.Text.Encoding.ASCII.GetBytes(readStream)

The aspx page is shown below. Can anyone help?
Thanks
Leslie

<%@ Page Language="VB" debug="True"%>
<%@ import namespace="system.io"%>
<%@ Import Namespace="System.Text" %>
<%@ import namespace="system.xml"%>
<%@ import Namespace="System.Net" %>
<%@ import Namespace="System.Web" %>
<Script Language="vb" runat="server">
Sub Page_Load(s as object, e as eventargs)

'Creates a streamreader from an xml file
Dim HttpWReq As HttpWebRequest =
CType(WebRequest.Create("http://server/datafile.xml"), HttpWebRequest)
Dim HttpWResp As HttpWebResponse = CType(HttpWReq.GetResponse(),
HttpWebResponse)
Dim receiveStream As Stream = HttpWResp.GetResponseStream()
Dim encode As Encoding =
system.Text.Encoding.GetEncoding("ISO-8859-1")
Dim readStream As New StreamReader(receiveStream, encode)

'post readstream to target server
Dim web As New System.Net.WebClient()
web.Headers.Add("Content-Type", "text/xml")
Dim d As Byte() = System.Text.Encoding.ASCII.GetBytes(readStream)
Dim res As Byte() = web.UploadData("http://targetserver/postpage",
"POST", d)
Console.Write(System.Text.Encoding.ASCII.GetString (res))
response.write (System.Text.Encoding.ASCII.GetString(res))

readStream.Close()
HttpWResp.Close()

End Sub
</script>

Nov 20 '05 #1
16 3830
ASCIIEncoding.GetBytes encodes a Unicode character array or a string. You're passing a StreamReader, which is not among the overloads availble for this method. The list of available overloads is here

http://msdn.microsoft.com/library/de...bytestopic.asp
Nov 20 '05 #2
<les> schrieb

BC30518: Overload resolution failed because no accessible
'GetBytes' can be called with these arguments:

Line 20: Dim d As Byte() =
System.Text.Encoding.ASCII.GetBytes(readStream)


Right, you can not pass a stream to the GetBytes method. Pass a String or an
array of Chars.
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #3
les
Thanks Armin, but I'm a bit lost here. How would I change my code to
pass a string or array of chars?

Thanks
Leslie
On Sat, 24 Apr 2004 01:16:04 +0200, "Armin Zingler"
<az*******@freenet.de> wrote:
<les> schrieb

BC30518: Overload resolution failed because no accessible
'GetBytes' can be called with these arguments:

Line 20: Dim d As Byte() =
System.Text.Encoding.ASCII.GetBytes(readStream)


Right, you can not pass a stream to the GetBytes method. Pass a String or an
array of Chars.


<%@ Page Language="VB" debug="True"%>
<%@ import namespace="system.io"%>
<%@ Import Namespace="System.Text" %>
<%@ import namespace="system.xml"%>
<%@ import Namespace="System.Net" %>
<%@ import Namespace="System.Web" %>
<Script Language="vb" runat="server">
Sub Page_Load(s as object, e as eventargs)

'Creates a streamreader from an xml file
Dim HttpWReq As HttpWebRequest =
CType(WebRequest.Create("http://server/datafile.xml"), HttpWebRequest)
Dim HttpWResp As HttpWebResponse = CType(HttpWReq.GetResponse(),
HttpWebResponse)
Dim receiveStream As Stream = HttpWResp.GetResponseStream()
Dim encode As Encoding =
system.Text.Encoding.GetEncoding("ISO-8859-1")
Dim readStream As New StreamReader(receiveStream, encode)

'post readstream to target server
Dim web As New System.Net.WebClient()
web.Headers.Add("Content-Type", "text/xml")
Dim d As Byte() = System.Text.Encoding.ASCII.GetBytes(readStream)
Dim res As Byte() = web.UploadData("http://targetserver/postpage",
"POST", d)
Console.Write(System.Text.Encoding.ASCII.GetString (res))
response.write (System.Text.Encoding.ASCII.GetString(res))

readStream.Close()
HttpWResp.Close()

End Sub
</script>
Nov 20 '05 #4
<les> schrieb
Thanks Armin, but I'm a bit lost here. How would I change my code
to pass a string or array of chars?


When you create the Streamreader, you can pass an Encoding object that
specifies the encoding of the chars in the stream. After reading a string
from the Stream, you can pass it to the GetBytes method of an Encoding
object to get the encoded byte array.
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #5
les
I'm creating the streamreader ok , but can't work out how to do the
rest. This bit encodes the stream as iso-8859-1, but how do I convert
this to a string?

system.Text.Encoding.GetEncoding("ISO-8859-1")
Dim readStream As New StreamReader(receiveStream, encode)
On Sat, 24 Apr 2004 16:57:22 +0200, "Armin Zingler"
<az*******@freenet.de> wrote:
<les> schrieb
Thanks Armin, but I'm a bit lost here. How would I change my code
to pass a string or array of chars?


When you create the Streamreader, you can pass an Encoding object that
specifies the encoding of the chars in the stream. After reading a string
from the Stream, you can pass it to the GetBytes method of an Encoding
object to get the encoded byte array.


<Script Language="vb" runat="server">
Sub Page_Load(s as object, e as eventargs)

'Creates a streamreader from an xml file
Dim HttpWReq As HttpWebRequest =
CType(WebRequest.Create("http://server/datafile.xml"), HttpWebRequest)
Dim HttpWResp As HttpWebResponse = CType(HttpWReq.GetResponse(),
HttpWebResponse)
Dim receiveStream As Stream = HttpWResp.GetResponseStream()
Dim encode As Encoding =
system.Text.Encoding.GetEncoding("ISO-8859-1")
Dim readStream As New StreamReader(receiveStream, encode)

'post readstream to target server
Dim web As New System.Net.WebClient()
web.Headers.Add("Content-Type", "text/xml")
Dim d As Byte() = System.Text.Encoding.ASCII.GetBytes(readStream)
Dim res As Byte() = web.UploadData("http://targetserver/postpage",
"POST", d)
Console.Write(System.Text.Encoding.ASCII.GetString (res))
response.write (System.Text.Encoding.ASCII.GetString(res))

readStream.Close()
HttpWResp.Close()

End Sub
</script>
Nov 20 '05 #6
<les> schrieb
I'm creating the streamreader ok , but can't work out how to do
the rest. This bit encodes the stream as iso-8859-1, but how do I
convert this to a string?

system.Text.Encoding.GetEncoding("ISO-8859-1")
Dim readStream As New StreamReader(receiveStream, encode)


What do you want to convert to a string? If the text in the stream is
encoded in "ISO-8859-1", you can now use the stream to read from
(readStream.readline or readStream.readtoend).

Later you can convert the string to a byte array by passing it to the
GetBytes method of an Encoding object.
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #7
les
Now I'm really confused....I thought you were telling me I need to
convert the streamreader to a string before it can be passed to the
getbytes method.

Is it possible you could show me how to modify the code? I'm quite
lost here
Thanks
Leslie
On Sat, 24 Apr 2004 17:36:43 +0200, "Armin Zingler"
<az*******@freenet.de> wrote:
<les> schrieb
I'm creating the streamreader ok , but can't work out how to do
the rest. This bit encodes the stream as iso-8859-1, but how do I
convert this to a string?

system.Text.Encoding.GetEncoding("ISO-8859-1")
Dim readStream As New StreamReader(receiveStream, encode)


What do you want to convert to a string? If the text in the stream is
encoded in "ISO-8859-1", you can now use the stream to read from
(readStream.readline or readStream.readtoend).

Later you can convert the string to a byte array by passing it to the
GetBytes method of an Encoding object.

<Script Language="vb" runat="server">
Sub Page_Load(s as object, e as eventargs)
'Creates a streamreader from an xml file
Dim HttpWReq As HttpWebRequest =
CType(WebRequest.Create("http://server/datafile.xml"), HttpWebRequest)
Dim HttpWResp As HttpWebResponse = CType(HttpWReq.GetResponse(),
HttpWebResponse)
Dim receiveStream As Stream = HttpWResp.GetResponseStream()
Dim encode As Encoding =
system.Text.Encoding.GetEncoding("ISO-8859-1")
Dim readStream As New StreamReader(receiveStream, encode)

'post readstream to target server
Dim web As New System.Net.WebClient()
web.Headers.Add("Content-Type", "text/xml")
Dim d As Byte() = System.Text.Encoding.ASCII.GetBytes(readStream)
Dim res As Byte() = web.UploadData("http://targetserver/postpage",
"POST", d)
Console.Write(System.Text.Encoding.ASCII.GetString (res))
response.write (System.Text.Encoding.ASCII.GetString(res))

readStream.Close()
HttpWResp.Close()

End Sub
</script>
Nov 20 '05 #8
<les> schrieb
Now I'm really confused....I thought you were telling me I need to
convert the streamreader to a string before it can be passed to
the getbytes method.

Is it possible you could show me how to modify the code? I'm quite
lost here


I don't know what's your intention. You wanted to get the bytes from a
stream in a certain encoding, right?
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #9
les
On Sat, 24 Apr 2004 20:00:49 +0200, "Armin Zingler"
<az*******@freenet.de> wrote:
<les> schrieb
Now I'm really confused....I thought you were telling me I need to
convert the streamreader to a string before it can be passed to
the getbytes method.

Is it possible you could show me how to modify the code? I'm quite
lost here


I don't know what's your intention. You wanted to get the bytes from a
stream in a certain encoding, right?


Yes but getting the following error:

BC30518: Overload resolution failed because no accessible 'GetBytes'
can be called with these arguments:

Line 20: Dim d As Byte() =
System.Text.Encoding.ASCII.GetBytes(readStream)
<%@ Page Language="VB" debug="True"%>
<%@ import namespace="system.io"%>
<%@ Import Namespace="System.Text" %>
<%@ import namespace="system.xml"%>
<%@ import Namespace="System.Net" %>
<%@ import Namespace="System.Web" %>
<Script Language="vb" runat="server">
Sub Page_Load(s as object, e as eventargs)

'Creates a streamreader from an xml file
Dim HttpWReq As HttpWebRequest =
CType(WebRequest.Create("http://server/datafile.xml"), HttpWebRequest)
Dim HttpWResp As HttpWebResponse = CType(HttpWReq.GetResponse(),
HttpWebResponse)
Dim receiveStream As Stream = HttpWResp.GetResponseStream()
Dim encode As Encoding =
system.Text.Encoding.GetEncoding("ISO-8859-1")
Dim readStream As New StreamReader(receiveStream, encode)

'post readstream to target server
Dim web As New System.Net.WebClient()
web.Headers.Add("Content-Type", "text/xml")
Dim d As Byte() = System.Text.Encoding.ASCII.GetBytes(readStream)
Dim res As Byte() = web.UploadData("http://targetserver/postpage",
"POST", d)
Console.Write(System.Text.Encoding.ASCII.GetString (res))
response.write (System.Text.Encoding.ASCII.GetString(res))

readStream.Close()
HttpWResp.Close()

End Sub
</script>

Nov 20 '05 #10
<les> schrieb
On Sat, 24 Apr 2004 20:00:49 +0200, "Armin Zingler"
<az*******@freenet.de> wrote:
<les> schrieb
Now I'm really confused....I thought you were telling me I need
to convert the streamreader to a string before it can be passed
to the getbytes method.

Is it possible you could show me how to modify the code? I'm
quite lost here


I don't know what's your intention. You wanted to get the bytes from
a stream in a certain encoding, right?


Yes but getting the following error:


Now we are as far as yesterday.

What do you want to do?? What is your intention??

You can NOT pass a streamreader to the GetBytes function. You can pass a
string to the GetBytes function. I don't know which string you want to pass.
I assume, you first want to read the string from the Streamreader and then
pass it to GetBytes. Is this right or wrong? If it is right, use the
Streamreaders ReadLine or Readtoend method. Then you have a string and you
can pass it to GetBytes. Where is the problem with doing it? Or is it not
what you want to do? I don't know.
--
Armin

Nov 20 '05 #11
les
Thanks for persevering with me Armin.
It sounds like you are describing exactly what I want to do, but I
don't know how to apply the ReadLine or Readtoend method to my
existing code.
Leslie
On Sat, 24 Apr 2004 20:18:39 +0200, "Armin Zingler"
<az*******@freenet.de> wrote:
<les> schrieb
On Sat, 24 Apr 2004 20:00:49 +0200, "Armin Zingler"
<az*******@freenet.de> wrote:
><les> schrieb
>> Now I'm really confused....I thought you were telling me I need
>> to convert the streamreader to a string before it can be passed
>> to the getbytes method.
>>
>> Is it possible you could show me how to modify the code? I'm
>> quite lost here
>
>I don't know what's your intention. You wanted to get the bytes from
> a stream in a certain encoding, right?


Yes but getting the following error:


Now we are as far as yesterday.

What do you want to do?? What is your intention??

You can NOT pass a streamreader to the GetBytes function. You can pass a
string to the GetBytes function. I don't know which string you want to pass.
I assume, you first want to read the string from the Streamreader and then
pass it to GetBytes. Is this right or wrong? If it is right, use the
Streamreaders ReadLine or Readtoend method. Then you have a string and you
can pass it to GetBytes. Where is the problem with doing it? Or is it not
what you want to do? I don't know.


Nov 20 '05 #12
<les> schrieb
Thanks for persevering with me Armin.
It sounds like you are describing exactly what I want to do, but I
don't know how to apply the ReadLine or Readtoend method to my
existing code.
Leslie

You don't know how to call a method?

- WebRequest.Create
- HttpWReq.GetResponse
- HttpWResp.GetResponseStream
- Encoding.GetEncoding

These are all method calls in your code, so I think you do know how to call
a method. Sorry, I don't understand.
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #13
dim s as string
dim d as byte()

s = readStream.Readline

d = System.Text.Encoding.ASCII.GetBytes(s)

This reads a line, then gets the bytes encoded using ASCII encoding.
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #14
les
I'm not sure I can describe the problem any better. I don't have much
experience of vb.net, so I'm hoping someone can show how to change my
code to use readline or readtoend as you sugested.
On Sat, 24 Apr 2004 20:38:00 +0200, "Armin Zingler"
<az*******@freenet.de> wrote:
<les> schrieb
Thanks for persevering with me Armin.
It sounds like you are describing exactly what I want to do, but I
don't know how to apply the ReadLine or Readtoend method to my
existing code.
Leslie

You don't know how to call a method?

- WebRequest.Create
- HttpWReq.GetResponse
- HttpWResp.GetResponseStream
- Encoding.GetEncoding

These are all method calls in your code, so I think you do know how to call
a method. Sorry, I don't understand.


Nov 20 '05 #15
<les> schrieb
I'm not sure I can describe the problem any better. I don't have
much experience of vb.net, so I'm hoping someone can show how to
change my code to use readline or readtoend as you sugested.


You don't tell me what you want, so I can't help you.

--
Armin

Nov 20 '05 #16
les
That's what I needed. Thanks again Armin for your help.

Leslie

On Sat, 24 Apr 2004 20:41:25 +0200, "Armin Zingler"
<az*******@freenet.de> wrote:
dim s as string
dim d as byte()

s = readStream.Readline

d = System.Text.Encoding.ASCII.GetBytes(s)

This reads a line, then gets the bytes encoded using ASCII encoding.


Nov 20 '05 #17

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by cloudx | last post: by
reply views Thread by tshad | last post: by
3 posts views Thread by tshad | last post: by
10 posts views Thread by tshad | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by kmladenovski | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.