HttpWebRequest


E

EMonaco

I am very frustrated trying to use .NET's HttpWebRequest. Does anybody know
where I can find "GOOD" HttpWebRequest documentation and samples? The
microsoft ones are woefully inadequate and my last few posts have gone
unanswered. You can check my earlier posts if you'd like to see the areas I
am having problems with.


Erin.
 
Ad

Advertisements

E

EMonaco

Jerry III,
Based on your previous posts I think you don't understand the purpose of
that object. It does not allow you to create and send a web request as you
think, it's actually part of an ASP.NET page processing (it contains
information about the request being processed).

Huh? "It does not allow you to create and send a web request..."? Sure it
does. And all the examples on doing client GET/POST/PROXY/SSL etc. in
microsoft's quick start guides use HttpWebRequest and HttpWebResponse
objects!

If this is in fact the case however- how should I be doing client side web
request (like WinINet)?


Erin.
 
E

EMonaco

Rick,

While your document is much better than Microsoft's, it still does not
answer any of my outstanding questions, of which I will summarize:

1) Need to gzip post data for transport- having the server gunzip it before
persisting data. (ie; transfer-encoding)

Problems here: setting transfer-encoding: says I have to set SendChunked =
true. When I do this while adding the header, the .SendChunked property goes
back to false (even though HttpWebRequest is shuttled around as (ref). I
have to explicitly remember it and set it again before calling
..GetResponse() otherwise I get the same exception as trying to add the
header.

HTTP 1.1 spec says "chunked" must follow other tokens when using
"transfer-encoding", so trying to do "Transfer-Encoding: gzip;chunked" I get
another exception saying I have to set the Chunked property. Only I didn't
find a chunked property (I am setting SendChunked=true.

As a test I've just saved the raw form data to a .txt file- using a
freeware package, I've gzip'd that to form_data.gz, in my post routine I
read the contents of this .gz file into a byte [] and write that to the
HttpWebRequest.GetRequestStream() stream.

At last I get a response from the server- but upon checking for the posted
data- it's blank!

2) How can I determine at runtime if a URL I'm going to requires a client
cert. The only thing I am able to get is the 403 Forbidden? And along these
lines- say I send a request and it comes back with 407 Proxy Authentication,
what do I need to do exactly to be able to re-use the HttpWebRequest
instance, setting credentials of course, to resubmit the original request?

3) I've implemented a class that inherits the ICertificatePolicy interface.
I then set ServicePointManager.CertificatePolicy = this. In my
CheckValidationResult(), I log server cert info and return true. Now say for
example, the CN name on the server cert does not match the site name, my
CheckValidationResult() function is called. After returning true, if I go to
the same site- my CheckValidationResult() is not called again. I assume
because I returned true, and it has cached that information.

My question is can I change this behavior so it will always call my
CheckValidationResult() on each new request, if there is a cert problem?
I've checked ServicePointManger and ServicePoint but do not see any method
that would clear, flush, reset, etc. this information.

Regards,
Erin.
 
R

Rick Strahl [MVP]

Sorry don't know the answer to those questions. I suspect those are covered
somewhere in KB articles, but don't know...

There are so many different things people want to do it's difficult to cover
it all in one place <g>. Certainly I can see why your questions aren't
covered in the docs. If worst comes to worse MSDN Support should be able to
get you in contact with people at MS that can answer these very specialized
questions...

+++ Rick ---

--

Rick Strahl
West Wind Technologies
http://www.west-wind.com/
http://www.west-wind.com/wwHelp
----------------------------------
Making waves on the Web


EMonaco said:
Rick,

While your document is much better than Microsoft's, it still does not
answer any of my outstanding questions, of which I will summarize:

1) Need to gzip post data for transport- having the server gunzip it before
persisting data. (ie; transfer-encoding)

Problems here: setting transfer-encoding: says I have to set SendChunked =
true. When I do this while adding the header, the .SendChunked property goes
back to false (even though HttpWebRequest is shuttled around as (ref). I
have to explicitly remember it and set it again before calling
.GetResponse() otherwise I get the same exception as trying to add the
header.

HTTP 1.1 spec says "chunked" must follow other tokens when using
"transfer-encoding", so trying to do "Transfer-Encoding: gzip;chunked" I get
another exception saying I have to set the Chunked property. Only I didn't
find a chunked property (I am setting SendChunked=true.

As a test I've just saved the raw form data to a .txt file- using a
freeware package, I've gzip'd that to form_data.gz, in my post routine I
read the contents of this .gz file into a byte [] and write that to the
HttpWebRequest.GetRequestStream() stream.

At last I get a response from the server- but upon checking for the posted
data- it's blank!

2) How can I determine at runtime if a URL I'm going to requires a client
cert. The only thing I am able to get is the 403 Forbidden? And along these
lines- say I send a request and it comes back with 407 Proxy Authentication,
what do I need to do exactly to be able to re-use the HttpWebRequest
instance, setting credentials of course, to resubmit the original request?

3) I've implemented a class that inherits the ICertificatePolicy interface.
I then set ServicePointManager.CertificatePolicy = this. In my
CheckValidationResult(), I log server cert info and return true. Now say for
example, the CN name on the server cert does not match the site name, my
CheckValidationResult() function is called. After returning true, if I go to
the same site- my CheckValidationResult() is not called again. I assume
because I returned true, and it has cached that information.

My question is can I change this behavior so it will always call my
CheckValidationResult() on each new request, if there is a cert problem?
I've checked ServicePointManger and ServicePoint but do not see any method
that would clear, flush, reset, etc. this information.

Regards,
Erin.

Rick Strahl said:
Maybe this will help:
http://www.west-wind.com/presentations/dotnetWebRequest/dotnetWebRequest.htm
This article talks about a lot of non-obvious things that aren't covered in
the docs.

+++ Rick ---

--

Rick Strahl
West Wind Technologies
http://www.west-wind.com/
http://www.west-wind.com/wwHelp
 
Ad

Advertisements

F

feroze

1) Try the following: ( you did not attach code, so I dont know if you tried
this already )

request.SendChunked = true
request.TransferEncoding = "gzip/deflate"

2) There is no way to reuse the webrequest. you need to create a new
httpwebrequest and set the correct credentials on it.

3) SSL certificate checking happens once per connection establishment. This
is a SSL specification. So, if you chose to ignore the cert error, the
connection gets established. If a subsequent request uses the already
established connection, your handler wont be called. If you want the handler
to be called for every request, you can either a) set KeepAlive = false, b)
use a new connectiongroupname for each request. Both of these will cause a
new connection to be established for each request, which is not very
optimal. Why do you want to be triggered for every request ? Do you expect
something to change on the server between one request and the next ?

feroze.


EMonaco said:
Rick,

While your document is much better than Microsoft's, it still does not
answer any of my outstanding questions, of which I will summarize:

1) Need to gzip post data for transport- having the server gunzip it before
persisting data. (ie; transfer-encoding)

Problems here: setting transfer-encoding: says I have to set SendChunked =
true. When I do this while adding the header, the .SendChunked property goes
back to false (even though HttpWebRequest is shuttled around as (ref). I
have to explicitly remember it and set it again before calling
.GetResponse() otherwise I get the same exception as trying to add the
header.

HTTP 1.1 spec says "chunked" must follow other tokens when using
"transfer-encoding", so trying to do "Transfer-Encoding: gzip;chunked" I get
another exception saying I have to set the Chunked property. Only I didn't
find a chunked property (I am setting SendChunked=true.

As a test I've just saved the raw form data to a .txt file- using a
freeware package, I've gzip'd that to form_data.gz, in my post routine I
read the contents of this .gz file into a byte [] and write that to the
HttpWebRequest.GetRequestStream() stream.

At last I get a response from the server- but upon checking for the posted
data- it's blank!

2) How can I determine at runtime if a URL I'm going to requires a client
cert. The only thing I am able to get is the 403 Forbidden? And along these
lines- say I send a request and it comes back with 407 Proxy Authentication,
what do I need to do exactly to be able to re-use the HttpWebRequest
instance, setting credentials of course, to resubmit the original request?

3) I've implemented a class that inherits the ICertificatePolicy interface.
I then set ServicePointManager.CertificatePolicy = this. In my
CheckValidationResult(), I log server cert info and return true. Now say for
example, the CN name on the server cert does not match the site name, my
CheckValidationResult() function is called. After returning true, if I go to
the same site- my CheckValidationResult() is not called again. I assume
because I returned true, and it has cached that information.

My question is can I change this behavior so it will always call my
CheckValidationResult() on each new request, if there is a cert problem?
I've checked ServicePointManger and ServicePoint but do not see any method
that would clear, flush, reset, etc. this information.

Regards,
Erin.

Rick Strahl said:
Maybe this will help:
http://www.west-wind.com/presentations/dotnetWebRequest/dotnetWebRequest.htm
This article talks about a lot of non-obvious things that aren't covered in
the docs.

+++ Rick ---

--

Rick Strahl
West Wind Technologies
http://www.west-wind.com/
http://www.west-wind.com/wwHelp
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top