Save data on Website

S

shantanu

Hi All

I need to update some data on a web page through the httpwebrequest.
For which i am writing the code below . Kindly tell me where the flaw
is as it is not updating the values.

Thanks and regards
Shantanu

WebNetCred = new System.Net.NetworkCredential("test","test123");
System.Uri uriDest = new Uri("http://aww.ngn.bel.alcatel.be/prp/
cgi-bin/secure/DRForm.cgi?root=AL&number=9YZ-00153-
ABAA&mode=update&dr0p.original=2003-02-28&dr0p.planned=&dr0p.status=&dr1.original=&dr1.planned=&dr1.status=&dr3.original=&dr3.planned=&dr3.status=&dr4.original=&dr4.planned=&dr4.status=&dr5.original=&dr5.planned=&dr5.status=&dr6.original=&dr6.planned=&dr6.status=&del1.original=&del1.planned=&del1.status=&del2.original=&del2.planned=&del2.status=&dr0.original=&dr0.planned=&dr0.status=&dr2.original=&dr2.planned=&dr2.status=&obr.original=&obr.planned=&obr.status=");

HttpWebRequest httpRequest =
(HttpWebRequest)WebRequest.Create(uriDest);

httpRequest.Method = "POST";
httpRequest.PreAuthenticate = true;
httpRequest.Credentials = WebNetCred;

httpRequest.Timeout = 150000;
httpRequest.KeepAlive = true;
httpRequest.ContentType = "application/x-www-form-urlencoded";
httpRequest.ContentLength = 0;// bytes.Length;
MessageBox.Show("2");

WebResponse response = httpRequest.GetResponse();
HttpWebResponse httpResponse = (HttpWebResponse)response;
System.IO.Stream stream = httpResponse.GetResponseStream();
System.IO.StreamReader readStream = new
System.IO.StreamReader(stream, System.Text.Encoding.UTF8);
string txt = readStream.ReadToEnd();
MessageBox.Show("3");
readStream.Close();
stream.Close();
MessageBox.Show("txt : " + txt);
MessageBox.Show("4");
 
S

shantanu

Couple of things I see right away:
1) You are using the http POST verb, but all your stuff is on the
querystring.
That's a GET.
2) your content length is specified as 0 bytes.

There are lots of examples of how to make a form POST with HttpWebRequest.
Let your fingers do the googling and you'll find them very quickly.

-- Peter
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net












- Show quoted text -

Thanks peter it worked
now i have a new question

i have written a code that will send a querystring to search data from
a webpage . If the values sent in the querystring matches the data or
dosent matches the data then it sends the whole web page. ijust want
to extraxt the result from the webpage. By any chance i can get it.
i am pasting the code below
Private Function AuthenticateUser()

Dim netCred As New NetworkCredential("test", "test002")
'Dim UriDest As New Uri("http://ldap.net.alcatel.com/Sc=IN?
S=shantanu%20sen")

Dim httpReq As HttpWebRequest
Dim WebReq As WebRequest

'httpReq.Create(UriDest)

httpReq = WebRequest.Create("http://ldap.net.alcatel.com/Sc=IN?
S=shantanu sen")


httpReq.Method = "GET"
httpReq.PreAuthenticate = True
httpReq.Credentials = netCred
httpReq.ContentType = "application/x-www-form-urlencoded"
'httpReq.ContentLength = 0

Dim response As WebResponse
response = httpReq.GetResponse()
Dim stream As System.IO.Stream
stream = response.GetResponseStream()
Dim ReadStream As New System.IO.StreamReader(stream,
System.Text.Encoding.UTF8)
Dim txt As String
txt = ReadStream.ReadToEnd
Return (txt)
End Function
 
Top