The underlying connection was closed. (HttpWebRequest)
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
add a comment |
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
Use Fiddler to debug this scenarios...
– Matías Fidemraizer
Sep 7 '15 at 8:21
thr url containshttps
scheme.Aren't you going to use any authentication?
– Amit Kumar Ghosh
Sep 10 '15 at 7:48
add a comment |
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
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
c# .net httprequest
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 containshttps
scheme.Aren't you going to use any authentication?
– Amit Kumar Ghosh
Sep 10 '15 at 7:48
add a comment |
Use Fiddler to debug this scenarios...
– Matías Fidemraizer
Sep 7 '15 at 8:21
thr url containshttps
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
add a comment |
1 Answer
1
active
oldest
votes
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();
+1 In .NET 4.0 (whereSecurityProtocolType.Tls12
is missing) you need to use(SecurityProtocolType) 0xc00
- see stackoverflow.com/a/51346252/47528
– Dan
Nov 15 '18 at 11:24
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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();
+1 In .NET 4.0 (whereSecurityProtocolType.Tls12
is missing) you need to use(SecurityProtocolType) 0xc00
- see stackoverflow.com/a/51346252/47528
– Dan
Nov 15 '18 at 11:24
add a comment |
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();
+1 In .NET 4.0 (whereSecurityProtocolType.Tls12
is missing) you need to use(SecurityProtocolType) 0xc00
- see stackoverflow.com/a/51346252/47528
– Dan
Nov 15 '18 at 11:24
add a comment |
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();
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();
answered Sep 10 '15 at 7:33
Vova PotapovVova Potapov
87542548
87542548
+1 In .NET 4.0 (whereSecurityProtocolType.Tls12
is missing) you need to use(SecurityProtocolType) 0xc00
- see stackoverflow.com/a/51346252/47528
– Dan
Nov 15 '18 at 11:24
add a comment |
+1 In .NET 4.0 (whereSecurityProtocolType.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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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