Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

JIRA REST: Timeout (System.Net.Sockets.SocketException)

Brian Loomis June 23, 2013

I am getting the following exception when attempting to connect to JIRA REST in C#:

"A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond."

Here is the code I am using:

public partial class Form1 : Form
    {
        string JIRAInstanceUri = (not sure if i can reveal this)
        System.Net.WebProxy ProxyServer = new System.Net.WebProxy();
        System.Net.HttpWebResponse Response = null;

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //Get user info and service
            UserName = txtUser.Text;
            Password = txtPassword.Text;
            ServiceUri = txtService.Text;

            //Create WebRequest
            Uri JsonUri = new Uri(new Uri(JIRAInstanceUri), ServiceUri);
            WebRequest RestWebRequest = WebRequest.Create(JsonUri);
            RestWebRequest.Method = "GET";
            RestWebRequest.ContentType = "application/json";
            //Add proxy to WebRequest
            ProxyServer.BypassArrayList.Add(JsonUri);
            RestWebRequest.Proxy = ProxyServer;
            //Setup authorization
            string Base64Credentials = GetEncodedCredentials(UserName, Password);
            RestWebRequest.Headers["Authorization"] = "Basic " + Base64Credentials;

            try
            {
                Response = RestWebRequest.GetResponse() as HttpWebResponse;

                if (Response.StatusCode == System.Net.HttpStatusCode.OK)
                {
                    using (Stream stream = Response.GetResponseStream())
                    {
                        StreamReader reader = new StreamReader(stream, Encoding.UTF8);
                        txtBox.Text = reader.ReadToEnd();
                    }
                }
            }
            catch (Exception ex)
            {
                txtBox.Text = ex.ToString();
            }
        }
     
        private string GetEncodedCredentials(String userName, String password)
        {
            string mergedCredentials = string.Format("{0}:{1}", userName, password);
            byte[] byteCredentials = UTF8Encoding.UTF8.GetBytes(mergedCredentials);
            return Convert.ToBase64String(byteCredentials);
        }
    }
}

Thank you for the help!

3 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
glivar tuno December 8, 2013

see here basics of socket programming http://csharp.net-informations.com/communications/csharp-socket-programming.htm c# socket programming , it will help you.

Glivar

0 votes
Patrick Li
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 23, 2013

This sounds like a network issue. My guess is either the proxy or the endpoint URI.

Brian Loomis June 24, 2013

If I comment out the sections with the proxy, I get the following exception:

The remote server returned an error: (407) Proxy Authentication Required.

If I copy the URI from my webrequest to Firefox I can reach it.

0 votes
Timothy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 23, 2013

What's the response code that you get?

Brian Loomis June 24, 2013

I don't believe I am getting one, but I may be overlooking it I am new to both C# and JIRA/REST.

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events