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
Ajit More
NA
569
335.3k
Error While Integrating API ?
Aug 7 2019 1:58 AM
Hi friends,
When I am trying to push xml to webapi with basic authorization. the following error occured.
"The underlying connection was closed: An unexpected error occurred on a send."
Code
string
URL =
"www.abc.com"
;
string
xml_RN =
"Some Xml File"
;
//Create a HttpWebRequest object
HttpWebRequest req_RN = (HttpWebRequest)WebRequest.Create(URL);
byte
[] AuthBytes = Encoding.ASCII.GetBytes(UserName +
":"
+ Password);
string
sAuth = Convert.ToBase64String(AuthBytes);
req_RN.Headers.Add(
"Authorization"
,
"Basic"
+ sAuth);
//Set the Credentials property
NetworkCredential cred =
new
NetworkCredential(UserName, Password);
req_RN.Credentials = cred;
req_RN.PreAuthenticate =
true
;
//Security Protocol
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12 | SecurityProtocolType.Ssl3;
ServicePointManager.Expect100Continue =
true
;
//Convert xml string to a byte array
byte
[] postDataBytes = Encoding.ASCII.GetBytes(xml_RN);
//Set the Method property
req_RN.Method =
"POST"
;
//Set the ContentType property of the "HttpWebRequest"
req_RN.ContentType =
"application/xml"
;
req_RN.Accept =
"application/xml"
;
//Set the ContentLength property of the "HttpWebRequest"
req_RN.ContentLength = postDataBytes.Length;
Stream requestStream = req_RN.GetRequestStream();
requestStream.Write(postDataBytes, 0, postDataBytes.Length);
requestStream.Close();
Reply
Answers (
3
)
On="1" and Off="2" within one click
Why can’t I Publish web site error warn ?