Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / .NET SDK / March 2005

Tip: Looking for answers? Try searching our database.

problem with httpWebRequest removing chars

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ross Newark - 18 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??

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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.