koresnordic
IS-IT--Management
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
Graham
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
Graham