c# .Net webrequest issue

I have two questions about "under the hood" processes executed by Webrequest and the getresponse method.

1) I have noticed while packet capturing that, when doing a webrequest with a payload, packets starting a TCP/IP connection are sent and received *before* the getresponse method?  I would have expected the payload to be cached and sent only when the getresponse was called?

2) I have a webrequest case that has me puzzled.  It is an HTTPS URI.  All proceeds as expected (443 TCP/IP connection made before getresponse called) until the getresponse is called.  When that happens, the process attempts to create a new TCP/IP connection to the server, this one being on port 80 (not HTTPS).  Since the request is not HTTPS, the server ignores it and the process times out with a "no response from server".

What would cause the getresponse method to spawn a new connection, and why would it send it via HTTP when the original connection was made via HTTPS?  The certificate for the server is valid, and I have tried turning off the check-certificate functionality.

Thanks for any insight on both questions.

Bryan Hunt
brhuntAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bill BachPresident and Btrieve GuruCommented:
Can you post the source code snippet? I wonder if a second (new) object is being used because of a typo, such as improper case. I've done this before myself, and errors like that can be hard to find.
0
brhuntAuthor Commented:
Here you go Bill:

WebRequest geocodeRequest = WebRequest.Create("https://apps.abc123.com/356A8F39-F50D-4248-8D94-67EF369A4AD7/APP/REST/Geocode");
geocodeRequest.Method = "POST";
geocodeRequest.ContentType = "application/json";
geocodeRequest.Headers.Add("oitoken", securityToken);

GeocodeRequest myGReq = new GeocodeRequest
{
    keyCustomer = "A Site",
    keyString = "A key",
    addressList = new string[] { "123 W. Main St., Anywhere, TX 12345" }
};

string a = JsonConvert.SerializeObject(myGReq);
byte[] byteArray = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(myGReq));
geocodeRequest.ContentLength = byteArray.Length;
Stream dataStream = geocodeRequest.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();

WebResponse geocodeResponse = geocodeRequest.GetResponse();
dataStream = geocodeResponse.GetResponseStream();
StreamReader reader = new StreamReader(dataStream);
string geocodeResponseFromServer = reader.ReadToEnd();
reader.Close();
dataStream.Close();

GeocodeResponse myGResp = JsonConvert.DeserializeObject<EZTGeocodeResponse>(geocodeResponseFromServer);

geocodeResponse.Close();
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.