Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

GetBytes() giving error HttpWebRequest cannot be converted to string

Status
Not open for further replies.

koresnordic

IS-IT--Management
Nov 28, 2002
422
GB
HI,

I am required to post via https to playtrade.com

However I have never posted to a website before. I picked pieces up from various websites (and from playtrade direct) and produced the code below:

Dim username As String = "[email address]"
Dim password As String = "[password]"
Dim uname As String = username + ":" + password
Dim encoding64 As New ASCIIEncoding()
Dim authstring = Convert.ToBase64String(encoding64.GetBytes(uname))



Dim Requesturl As String = " Dim postreq As HttpWebRequest = DirectCast(WebRequest.Create(Requesturl), HttpWebRequest)
postreq.Method = "POST"
postreq.KeepAlive = False
postreq.ContentType = "text/xml"
postreq.Headers.Set("Authorization", authstring)
postreq.Headers.Set("ReportName", "Order")
postreq.Headers.Set("NumberOfDays", "1")

Dim encoding As New UTF8Encoding
Dim bytedata As Byte() = encoding.GetBytes(postreq) 'Dim encoding As New UTF8Encoding
postreq.ContentLength = bytedata.Length
Dim postreqstream As Stream = postreq.GetRequestStream()
postreqstream.Write(bytedata, 0, bytedata.Length)
postreqstream.Close()


Dim responsedata As String

Dim hwresponse As Net.HttpWebResponse = postreq.GetResponse()
If hwresponse.StatusCode = Net.HttpStatusCode.OK Then
Dim responseStream As IO.StreamReader = _
New IO.StreamReader(hwresponse.GetResponseStream())
responsedata = responseStream.ReadToEnd()
End If
hwresponse.Close()

TextBox1.Text = responsedata

but the line "Dim bytedata As Byte() = encoding.GetBytes(postreq)" gives me the error below
Overload resolution failed because no accessible 'GetBytes' can be called with these arguments:
'Public Overridable Function GetBytes(s As String) As Byte()': Value of type 'System.Net.HttpWebRequest' cannot be converted to 'String'.
'Public Overridable Function GetBytes(chars() As Char) As Byte()': Value of type 'System.Net.HttpWebRequest' cannot be converted to '1-dimensional array of Char'.

I am hoping someone can give me a clue

thanks

[pc]

Graham
 
Sorted myself don't worry,

changed Dim bytedata As Byte() = encoding.GetBytes(postreq)

to Dim bytedata As Byte() = encoding.GetBytes(Requesturl)

[pc]

Graham
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top