TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Rajveer singh
714
1k
248.9k
connection was closed: An unexpected error on receive
Sep 6 2019 7:22 AM
Hi all,
C# HttpWebRequest The underlying connection was closed: An unexpected error occurred on a receive.
trying all the solutions but not
get the solution.
OS:
Windows 10 pro
server support this TLS version
1st method
public
void
GET_request()
{
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12
HttpWebRequest req = (HttpWebRequest)(HttpWebRequest.Create(url));
req.Method =
"POST"
;
req.KeepAlive =
false
;
req.ContentType =
"application/xml"
;
req.ProtocolVersion = HttpVersion.Version10;
req.Headers.Set(HttpRequestHeader.Authorization,
"Basic abcd15243"
);
string
content = XDAuth.OuterXml;
req.ContentLength = content.Length;
Stream wri =
null
;
using
(wri = req.GetRequestStream())
{
byte
[] array = Encoding.UTF8.GetBytes(content);
wri.Write(array, 0, array.Length);
}
wri.Flush();
wri.Close();
string
resultData =
""
;
using
(HttpWebResponse HttpWResp = (HttpWebResponse)req.GetResponse())
{
int
resCode = (
int
)HttpWResp.StatusCode;
using
(Stream stream = HttpWResp.GetResponseStream())
{
using
(StreamReader reader =
new
StreamReader(stream))
{
resultData = reader.ReadToEnd();
}
}
}
}
2nd method
protected
override
WebRequest GetWebRequest(Uri address)
{
WebRequest webRequest =
base
.GetWebRequest(address)
as
WebRequest;
if
(webRequest ==
null
)
{
return
base
.GetWebRequest(address);
}
webRequest.Method =
"POST"
;
webRequest.ContentType =
"Application/xml"
;
webRequest.Headers.Set(HttpRequestHeader.Authorization,
"Basic abcd15243"
);
//webRequest.CookieContainer = Cookies;
return
webRequest;
}
Reply
Answers (
2
)
Various textboxes
How do i add emoji in Email Subject ?