I am trying to connect to a php apache 2.2.1 webservice like this:
protected override WebRequest GetWebRequest(Uri uri)
{
var req = base.GetWebRequest(uri);
var http = req as HttpWebRequest;
if (http != null)
{
http.Connection = "Close";
http.ServicePoint.Expect100Continue = false;
}
return req;
}
But I received an System.ArgumentException mean as following "Keep-Alive and Close cannot be set"(This message has been translated from Japanese).
I have no idea why this exception is thrown. I have searched in MSDN and there is an explanation like this Exception Condition: The value of Connection is set to Keep-alive or Close.. In this case my httpWebRequest.Connection is null.
Do you have any idea about the reason of this exception?
I cannot explain why setting HttpWebRequest.Connection to Close or Keep-alive throw an ArgumentException. But we can set the Connection header to Close via the setting HttpWebRequest.KeepAlive to false.
More infos here : https://learn.microsoft.com/en-us/dotnet/api/system.net.httpwebrequest.connection?view=netframework-4.7.2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With