Unable to connect to the remote server

Asked 1 years ago, Updated 1 years ago, 41 views

Developing APIs for Visual Studio 2013, C#.

The purpose of the API is to send a message to your phone, which was initially a TimeOut error, but

req.Timeout=System.Threading.Timeout.Infinite;

When I added the above description, I got the error Unable to connect to the remote server.
What is the cause and how can I resolve this error?

public string SendSMS(string_message, string_phone_number)
{
    varenc=System.Text.Encoding.GetEncoding("EUC-JP");
    var postData="";

    try
    {
        // Create a string to POST
        postData=postData+String.Format("username={0}&", HttpUtility.UrlEncode(_username)));
        postData=postData+String.Format("password={0}&", HttpUtility.UrlEncode(_password)));
        postData=postData+String.Format("trigger_id={0}&", HttpUtility.UrlEncode(_trigger_id1));
        postData=postData+String.Format("phone_number={0}&", HttpUtility.UrlEncode(_PhoneNumber));
        postData=postData+String.Format("message={0}&", HttpUtility.UrlEncode(_message)));

        // Replace with byte array
        var postDataBytes=System.Text.Encoding.ASCII.GetBytes(postData);
        // Create WebRequest
        System.Net.WebRequest req = System.Net.WebRequest.Create(_SMSURL);

        req.Timeout = System.Threading.Timeout.Infinite;

        // Specify POST for the method
        req.Method="POST";
        // Set ContentType to "application/x-www-form-urlencoded"
        req.ContentType="application/x-www-form-urlencoded";
        // Specify the length of data to POST
        req.ContentLength=postDataBytes.Length;
        // Get Stream to POST data
        System.IO.Stream reqStream=req.GetRequestStream();

        // Write data to send
        reqStream.Write (postDataBytes, 0, postDataBytes.Length);

        reqStream.Close();

        // Get WebResponse to receive responses from the server
        varres=req.GetResponse();
        // Get Stream to receive response data
        varresStream=res.GetResponseStream();
        // To XML format
        varobjXMLReader=newXmlTextReader(resStream);

        var xmldoc = new XmlDocument();
        xmldoc.Load(objXMLReader);
        objXMLReader.Close();
    }
    catch (Exception e)
    {
        return "Send SMS Error" + e.Message + "log:" +_log;
    }
}

c# visual-studio network

2022-09-29 21:19

2 Answers

This may be an SSL/TLS version issue.

ServicePointManager.SecurityProtocol|=SecurityProtocolType.Tls11|SecurityProtocolType.Tls12;

Try adding .


2022-09-29 21:19

Rejected by the other server or
I think it's because I can't get out of my device.

Firewall settings allow (not denied) this communication
Why don't you check it out?


2022-09-29 21:19

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.