Had a problem with the webclient class - timeout.
So i have switched to the httpWebRequest. Followed all guides on internet and have tried sending bytes and text but whenever I send an SQL statement the spaces get stripped out??
code:
Dim encoding As New System.Text.ASCIIEncoding
Dim postData As New System.Text.StringBuilder
Dim tempStr As String
With postData 'value pairs
.Append("REQUEST=")
.Append("NoReturn")
.Append("&SQL=")
.Append(SQLUploadStr)
End With
tempStr = postData.ToString
'tempStr would be - "REQUEST=NoReturn&SQL=insert into resources(resname,resdata) Values('DDL_Location','brighton
')"
'Dim data As Byte() = encoding.GetBytes(tempStr)
Dim request As System.Net.HttpWebRequest = CType(WebRequest.Create(courseURL), HttpWebRequest)
With request
'.Create(courseURL)
.Method = "POST"
.ContentType = "application/x-www-form-urlencoded"
'.ContentLength = tempStr.Length
.AllowWriteStreamBuffering = True
End With
Dim reqStream As System.IO.Stream = request.GetRequestStream
'sw.Write(data, 0, data.Length)
'sw.Close()
Dim wrTr As System.IO.StreamWriter = New StreamWriter(reqStream)
wrTr.WriteLine(tempStr)
wrTr.Close()
Dim response As System.Net.HttpWebResponse = request.GetResponse
Dim sr As New System.IO.StreamReader(response.GetResponseStream)
Dim result As String = sr.ReadToEnd
sr.Close()
Error - Result returns :
"ERROR: Could not execute SQL statement. (Invalid SQL statement; expected 'DELETE', 'INSERT', 'PROCEDURE', 'SELECT', or 'UPDATE'. insertintoresources(resname,resdata)Values('DDL_Location','brighton'))"
as you can see the sql statement gets squeezed up.
Can any one help me please!!
Joerg Jooss - 19 Mar 2005 12:16 GMT
> Had a problem with the webclient class - timeout.
>
> So i have switched to the httpWebRequest. Followed all guides on
> internet and have tried sending bytes and text but whenever I send an
> SQL statement the spaces get stripped out??
[...]
Technically, you always have to URL encode form data, even when using
POST. Many server-side APIs like ASP.NET and many servlet containers
are quite forgiving and will also process posted form data that is not
URL encoded, but I guess this is not true in your case.
Thus, try URL encoding your SQL statement before sending it, e.g. using
System.Web.HttpUtility.UrlEncode().
Cheers,

Signature
http://www.joergjooss.de
mailto:news-reply@joergjooss.de