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!
Community moderators have prevented the ability to post new answers.
see here basics of socket programming http://csharp.net-informations.com/communications/csharp-socket-programming.htm c# socket programming , it will help you.
Glivar
This sounds like a network issue. My guess is either the proxy or the endpoint URI.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
What's the response code that you get?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I don't believe I am getting one, but I may be overlooking it I am new to both C# and JIRA/REST.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Community moderators have prevented the ability to post new answers.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.