没有可访问的'GetBytes'可以用这些参数调用 [英] no accessible 'GetBytes' can be called with these arguments
问题描述
我正在尝试将xml数据发送到远程服务器,我得到这个
错误:
BC30518:重载解析失败,因为没有可以用以下参数调用$'$ GetBytes''
:
第20行:Dim d As Byte()=
System.Text.Encoding.ASCII.GetBytes(readStream)
aspx页面如下所示。任何人都可以帮忙吗?
谢谢
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)
''从xml文件创建一个streamreader
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()
昏暗编码As Encoding =
system.Text.Encoding.GetEncoding(" ISO-8859-1")
Dim readStream As New StreamReader(receiveStream,encode)
''将readstream发布到目标服务器
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&q uot;,d)
Console.Write(System.Text.Encoding.ASCII.GetString(res))
response.write(System.Text.Encoding.ASCII。 GetString(res))
readStream.Close()
HttpWResp.Close()
结束Sub
< / script>
ASCIIEncoding.GetBytes对Unicode字符数组或字符串进行编码。你正在传递一个StreamReader,它不属于这种方法可用的重载。可用重载列表在这里
http://msdn.microsoft.com/library/de...bytestopic.asp
< BLOCKQUOTE>< LES> schrieb
BC30518:重载解析失败,因为无法访问
''GetBytes''可以使用以下参数调用:
第20行:Dim d As Byte()=
System.Text.Encoding.ASCII.GetBytes(readStream)
对,你不能将流传递给GetBytes方法。传递一个字符串或一个
阵列的字符。
-
Armin
如何引用及原因:
http://www.plig.net/ nnq / nquote.html
http:// www .netmeister.org / news / learn2quote.html
谢谢阿明,但我有点迷失在这里。如何将我的代码更改为
传递字符串或字符数组?
谢谢
Leslie
2004年4月24日星期六01:16:04 +0200,Armin Zingler
< az ******* @ freenet.de>写道:
< les> schrieb
BC30518:重载解析失败,因为无法访问
''GetBytes''可以使用以下参数调用:
第20行:Dim d As Byte()=
System.Text.Encoding.ASCII.GetBytes(readStream)
对,你不能将流传递给GetBytes方法。传递一个字符串或一组字符。
<%@ 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)
''从xml文件创建一个streamreader
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()
昏暗编码As Encoding =
system.Text.Encoding.GetEncoding(" ISO-8859-1")
Dim readStream As New StreamReader(receiveStream,encode)
''将readstream发布到目标服务器
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&q uot;,d)
Console.Write(System.Text.Encoding.ASCII.GetString(res))
response.write(System.Text.Encoding.ASCII。 GetString(res))
readStream.Close()
HttpWResp.Close()
结束Sub
< / script>
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>
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
<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
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>
这篇关于没有可访问的'GetBytes'可以用这些参数调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!