webrequest sent twice
-
Hello I define a HtppWebRequest ending with the following lines : ... req.Credentials = new NetworkCredential(...); Stream theStream = req.GetRequestStream(); theStream.Write(bytes, 0, bytes.Length); theStream.Close(); req.GetResponse(); Then, the request is sent twice. A first time with the theStream.Write line, and a second one with the req.GetResponse() line. I have a 401 (unauthorized) response with the first request and a 403 (forbidden) with the second one. I Wonder if the 403 error is due to the previous 401. In any case, I would not to send the first request. Thanks for your help
-
Hello I define a HtppWebRequest ending with the following lines : ... req.Credentials = new NetworkCredential(...); Stream theStream = req.GetRequestStream(); theStream.Write(bytes, 0, bytes.Length); theStream.Close(); req.GetResponse(); Then, the request is sent twice. A first time with the theStream.Write line, and a second one with the req.GetResponse() line. I have a 401 (unauthorized) response with the first request and a 403 (forbidden) with the second one. I Wonder if the 403 error is due to the previous 401. In any case, I would not to send the first request. Thanks for your help
You only need to use the stream if you have parameter data to be written to the URL.
req.Credentials = new NetworkCredential(...);
req.GetResponse();Will do the trick.
-
You only need to use the stream if you have parameter data to be written to the URL.
req.Credentials = new NetworkCredential(...);
req.GetResponse();Will do the trick.
No, the GetResponse is not enough because I have data to write into the request. I don't know how to send data without the GetRequestStream.
-
No, the GetResponse is not enough because I have data to write into the request. I don't know how to send data without the GetRequestStream.
Apologise, put my reading glasses on..
-
Hello I define a HtppWebRequest ending with the following lines : ... req.Credentials = new NetworkCredential(...); Stream theStream = req.GetRequestStream(); theStream.Write(bytes, 0, bytes.Length); theStream.Close(); req.GetResponse(); Then, the request is sent twice. A first time with the theStream.Write line, and a second one with the req.GetResponse() line. I have a 401 (unauthorized) response with the first request and a 403 (forbidden) with the second one. I Wonder if the 403 error is due to the previous 401. In any case, I would not to send the first request. Thanks for your help
Sounds like a typical authentication challenge - the request doesn't send the credentials unless the server indicates that it needs to. Try setting the PreAuthenticate property[^] to
true
:req.Credentials = new NetworkCredential(...);
req.PreAuthenticate = true;
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
Sounds like a typical authentication challenge - the request doesn't send the credentials unless the server indicates that it needs to. Try setting the PreAuthenticate property[^] to
true
:req.Credentials = new NetworkCredential(...);
req.PreAuthenticate = true;
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
Thanks for your idea, but it doesn't work :-(. I have the same behavior : a 401 error followed by a 403.
-
Sounds like a typical authentication challenge - the request doesn't send the credentials unless the server indicates that it needs to. Try setting the PreAuthenticate property[^] to
true
:req.Credentials = new NetworkCredential(...);
req.PreAuthenticate = true;
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
I've just solved my problem. Le number of - characters was not good on the boundary line.