The underlying connection was closed. (HttpWebRequest)












2















I have a HttpWebRequest that was working, and after a few weeks, it suddenly stopped working and starts to throw an error:



Here is my code:




The underlying connection was closed: An unexpected error occurred on
a send




HttpWebRequest FirstRequest = null;
HttpWebRequest postRequest = null;
HttpWebResponse response = null;
try
{
FirstRequest = (HttpWebRequest)WebRequest.Create("https://my.emerchantpay.com");
FirstRequest.CookieContainer = new CookieContainer();
FirstRequest.CookieContainer = _cookies;
FirstRequest.Accept = @"text/html, application/xhtml+xml, */*";
FirstRequest.Referer = @"https://my.emerchantpay.com";
FirstRequest.Headers.Add("Accept-Language", "en-GB");
FirstRequest.UserAgent = @"Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0)";
FirstRequest.Host = @"my.emerchantpay.com";
response = (HttpWebResponse)FirstRequest.GetResponse();//here is error
}catch{}


What am I doing wrong?










share|improve this question

























  • Use Fiddler to debug this scenarios...

    – Matías Fidemraizer
    Sep 7 '15 at 8:21











  • thr url contains https scheme.Aren't you going to use any authentication?

    – Amit Kumar Ghosh
    Sep 10 '15 at 7:48
















2















I have a HttpWebRequest that was working, and after a few weeks, it suddenly stopped working and starts to throw an error:



Here is my code:




The underlying connection was closed: An unexpected error occurred on
a send




HttpWebRequest FirstRequest = null;
HttpWebRequest postRequest = null;
HttpWebResponse response = null;
try
{
FirstRequest = (HttpWebRequest)WebRequest.Create("https://my.emerchantpay.com");
FirstRequest.CookieContainer = new CookieContainer();
FirstRequest.CookieContainer = _cookies;
FirstRequest.Accept = @"text/html, application/xhtml+xml, */*";
FirstRequest.Referer = @"https://my.emerchantpay.com";
FirstRequest.Headers.Add("Accept-Language", "en-GB");
FirstRequest.UserAgent = @"Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0)";
FirstRequest.Host = @"my.emerchantpay.com";
response = (HttpWebResponse)FirstRequest.GetResponse();//here is error
}catch{}


What am I doing wrong?










share|improve this question

























  • Use Fiddler to debug this scenarios...

    – Matías Fidemraizer
    Sep 7 '15 at 8:21











  • thr url contains https scheme.Aren't you going to use any authentication?

    – Amit Kumar Ghosh
    Sep 10 '15 at 7:48














2












2








2








I have a HttpWebRequest that was working, and after a few weeks, it suddenly stopped working and starts to throw an error:



Here is my code:




The underlying connection was closed: An unexpected error occurred on
a send




HttpWebRequest FirstRequest = null;
HttpWebRequest postRequest = null;
HttpWebResponse response = null;
try
{
FirstRequest = (HttpWebRequest)WebRequest.Create("https://my.emerchantpay.com");
FirstRequest.CookieContainer = new CookieContainer();
FirstRequest.CookieContainer = _cookies;
FirstRequest.Accept = @"text/html, application/xhtml+xml, */*";
FirstRequest.Referer = @"https://my.emerchantpay.com";
FirstRequest.Headers.Add("Accept-Language", "en-GB");
FirstRequest.UserAgent = @"Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0)";
FirstRequest.Host = @"my.emerchantpay.com";
response = (HttpWebResponse)FirstRequest.GetResponse();//here is error
}catch{}


What am I doing wrong?










share|improve this question
















I have a HttpWebRequest that was working, and after a few weeks, it suddenly stopped working and starts to throw an error:



Here is my code:




The underlying connection was closed: An unexpected error occurred on
a send




HttpWebRequest FirstRequest = null;
HttpWebRequest postRequest = null;
HttpWebResponse response = null;
try
{
FirstRequest = (HttpWebRequest)WebRequest.Create("https://my.emerchantpay.com");
FirstRequest.CookieContainer = new CookieContainer();
FirstRequest.CookieContainer = _cookies;
FirstRequest.Accept = @"text/html, application/xhtml+xml, */*";
FirstRequest.Referer = @"https://my.emerchantpay.com";
FirstRequest.Headers.Add("Accept-Language", "en-GB");
FirstRequest.UserAgent = @"Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0)";
FirstRequest.Host = @"my.emerchantpay.com";
response = (HttpWebResponse)FirstRequest.GetResponse();//here is error
}catch{}


What am I doing wrong?







c# .net httprequest






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Sep 7 '15 at 8:21









Sam Walton

33




33










asked Sep 7 '15 at 8:12









Vova PotapovVova Potapov

87542548




87542548













  • Use Fiddler to debug this scenarios...

    – Matías Fidemraizer
    Sep 7 '15 at 8:21











  • thr url contains https scheme.Aren't you going to use any authentication?

    – Amit Kumar Ghosh
    Sep 10 '15 at 7:48



















  • Use Fiddler to debug this scenarios...

    – Matías Fidemraizer
    Sep 7 '15 at 8:21











  • thr url contains https scheme.Aren't you going to use any authentication?

    – Amit Kumar Ghosh
    Sep 10 '15 at 7:48

















Use Fiddler to debug this scenarios...

– Matías Fidemraizer
Sep 7 '15 at 8:21





Use Fiddler to debug this scenarios...

– Matías Fidemraizer
Sep 7 '15 at 8:21













thr url contains https scheme.Aren't you going to use any authentication?

– Amit Kumar Ghosh
Sep 10 '15 at 7:48





thr url contains https scheme.Aren't you going to use any authentication?

– Amit Kumar Ghosh
Sep 10 '15 at 7:48












1 Answer
1






active

oldest

votes


















3














After long research i found answer.



You need to add ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;



 ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
FirstRequest = (HttpWebRequest)WebRequest.Create("https://my.emerchantpay.com");
FirstRequest.CookieContainer = new CookieContainer();
FirstRequest.CookieContainer = _cookies;
FirstRequest.Accept = @"text/html, application/xhtml+xml, */*";
FirstRequest.Referer = @"https://my.emerchantpay.com";
FirstRequest.Headers.Add("Accept-Language", "en-GB");
FirstRequest.UserAgent = @"Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0)";
FirstRequest.Host = @"my.emerchantpay.com";

response = (HttpWebResponse)FirstRequest.GetResponse();





share|improve this answer
























  • +1 In .NET 4.0 (where SecurityProtocolType.Tls12 is missing) you need to use (SecurityProtocolType) 0xc00 - see stackoverflow.com/a/51346252/47528

    – Dan
    Nov 15 '18 at 11:24













Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f32433949%2fthe-underlying-connection-was-closed-httpwebrequest%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









3














After long research i found answer.



You need to add ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;



 ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
FirstRequest = (HttpWebRequest)WebRequest.Create("https://my.emerchantpay.com");
FirstRequest.CookieContainer = new CookieContainer();
FirstRequest.CookieContainer = _cookies;
FirstRequest.Accept = @"text/html, application/xhtml+xml, */*";
FirstRequest.Referer = @"https://my.emerchantpay.com";
FirstRequest.Headers.Add("Accept-Language", "en-GB");
FirstRequest.UserAgent = @"Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0)";
FirstRequest.Host = @"my.emerchantpay.com";

response = (HttpWebResponse)FirstRequest.GetResponse();





share|improve this answer
























  • +1 In .NET 4.0 (where SecurityProtocolType.Tls12 is missing) you need to use (SecurityProtocolType) 0xc00 - see stackoverflow.com/a/51346252/47528

    – Dan
    Nov 15 '18 at 11:24


















3














After long research i found answer.



You need to add ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;



 ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
FirstRequest = (HttpWebRequest)WebRequest.Create("https://my.emerchantpay.com");
FirstRequest.CookieContainer = new CookieContainer();
FirstRequest.CookieContainer = _cookies;
FirstRequest.Accept = @"text/html, application/xhtml+xml, */*";
FirstRequest.Referer = @"https://my.emerchantpay.com";
FirstRequest.Headers.Add("Accept-Language", "en-GB");
FirstRequest.UserAgent = @"Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0)";
FirstRequest.Host = @"my.emerchantpay.com";

response = (HttpWebResponse)FirstRequest.GetResponse();





share|improve this answer
























  • +1 In .NET 4.0 (where SecurityProtocolType.Tls12 is missing) you need to use (SecurityProtocolType) 0xc00 - see stackoverflow.com/a/51346252/47528

    – Dan
    Nov 15 '18 at 11:24
















3












3








3







After long research i found answer.



You need to add ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;



 ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
FirstRequest = (HttpWebRequest)WebRequest.Create("https://my.emerchantpay.com");
FirstRequest.CookieContainer = new CookieContainer();
FirstRequest.CookieContainer = _cookies;
FirstRequest.Accept = @"text/html, application/xhtml+xml, */*";
FirstRequest.Referer = @"https://my.emerchantpay.com";
FirstRequest.Headers.Add("Accept-Language", "en-GB");
FirstRequest.UserAgent = @"Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0)";
FirstRequest.Host = @"my.emerchantpay.com";

response = (HttpWebResponse)FirstRequest.GetResponse();





share|improve this answer













After long research i found answer.



You need to add ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;



 ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
FirstRequest = (HttpWebRequest)WebRequest.Create("https://my.emerchantpay.com");
FirstRequest.CookieContainer = new CookieContainer();
FirstRequest.CookieContainer = _cookies;
FirstRequest.Accept = @"text/html, application/xhtml+xml, */*";
FirstRequest.Referer = @"https://my.emerchantpay.com";
FirstRequest.Headers.Add("Accept-Language", "en-GB");
FirstRequest.UserAgent = @"Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0)";
FirstRequest.Host = @"my.emerchantpay.com";

response = (HttpWebResponse)FirstRequest.GetResponse();






share|improve this answer












share|improve this answer



share|improve this answer










answered Sep 10 '15 at 7:33









Vova PotapovVova Potapov

87542548




87542548













  • +1 In .NET 4.0 (where SecurityProtocolType.Tls12 is missing) you need to use (SecurityProtocolType) 0xc00 - see stackoverflow.com/a/51346252/47528

    – Dan
    Nov 15 '18 at 11:24





















  • +1 In .NET 4.0 (where SecurityProtocolType.Tls12 is missing) you need to use (SecurityProtocolType) 0xc00 - see stackoverflow.com/a/51346252/47528

    – Dan
    Nov 15 '18 at 11:24



















+1 In .NET 4.0 (where SecurityProtocolType.Tls12 is missing) you need to use (SecurityProtocolType) 0xc00 - see stackoverflow.com/a/51346252/47528

– Dan
Nov 15 '18 at 11:24







+1 In .NET 4.0 (where SecurityProtocolType.Tls12 is missing) you need to use (SecurityProtocolType) 0xc00 - see stackoverflow.com/a/51346252/47528

– Dan
Nov 15 '18 at 11:24






















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f32433949%2fthe-underlying-connection-was-closed-httpwebrequest%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Bressuire

Vorschmack

Quarantine