404 server not found exception when working with jira instance of type http://machinename:port

Automation Group January 13, 2016
Hi
The below code is working fine for JIRA machine having of type https://machinename
but the same code is throwing 404 server not found exception in response when I use a different JIRA machine of url  http://machinename and when I checked for the same in Mozilla rest client for post request it throws 403 forbidden error.
What changes do I need to do for the url's starting from http:// . Kindly let me know
Below is the code
string Url ="https://jiraasp.atlassian.net/rest/api/latest/issue/";
string base64Credentials = GetEncodedCredentials();         
HttpWebResponse response = null;
 HttpWebRequest request = WebRequest.Create(Url) as HttpWebRequest;
 
       request.ContentType ="application/json";
 
       request.MediaType ="application/json";
 
       request.Accept ="application/json";
 
       request.Method ="POST"; 
  request.Headers.Add("Authorization", "Basic " + base64Credentials);
 
byte[] data = Encoding.UTF8.GetBytes(objJIRAData.JsonString);
using (var requestStream = request.GetRequestStream())            {
                requestStream.Write(data, 0, data.Length);
                requestStream.Close();
            }
using (response = request.GetResponse() as HttpWebResponse)
            {
if (response.StatusCode != HttpStatusCode.OK)
                {
var reader = new StreamReader(response.GetResponseStream());
                    status = response.StatusCode.ToString();
string str = reader.ReadToEnd();
Console.WriteLine("The server returned '{0}'\n{1}", response.StatusCode, str);
var jss = new System.Web.Script.Serialization.JavaScriptSerializer();
var sData = jss.Deserialize<Dictionary<string, string>>(str);
                    JiraKeyValue = sData["key"].ToString();
                }
            }

 

1 answer

0 votes
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 13, 2016

First, check if the machine is even listening on http.  What do you get when you visit it with a browser?

Suggest an answer

Log in or Sign up to answer