[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Need Help - Unable to create an application from code using OpenShift RedHat REST API



Hi Team,

 

I am trying to  create an application using diy-0.1 cartridge  into OpenShift Red hat environment from my sample code which I have developed in C#.net. I am using OpenShift RedHat REST API for creating an application through code.

Below is my sample code –

 

        string url ="">https://openshift.redhat.com/broker/rest/domain/{0}/applications", cbDomains.Text); 

 

        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);          

        request.Method = "POST";

        request.Credentials = new NetworkCredential(USERNAME, PASSWORD);           

        string postData = "{\"name\": \"myapp\","

                    + "\"cartridges\": [{"

                    + "\"name\": \"diy-0.1\"}],"

                    + "\"scale\": false,"

                    + "\"gear_size\": \"small\"}";

 

        byte[] byteArray = Encoding.UTF8.GetBytes(postData);           

        request.ContentType = "application/x-www-form-urlencoded";           

        request.ContentLength = byteArray.Length;           

        Stream dataStream = request.GetRequestStream();           

        dataStream.Write(byteArray, 0, byteArray.Length);           

        dataStream.Close();           

        WebResponse response = request.GetResponse(); -------------------------------------- [Getting error on this line]         

        dataStream = response.GetResponseStream();           

        StreamReader reader = new StreamReader(dataStream);            

        string responseFromServer = reader.ReadToEnd();

        reader.Close();

        dataStream.Close();

        response.Close();

 

When I execute above code I am getting error – “The remote server returned an error: (406) Not Acceptable.” And when I change hightlighted line to  request.Accept = "application/x-www-form-urlencoded";  still I am getting same error code 406.

And when I change code to request.Accept = "application/json"  then   I am getting error “The remote server returned an error: (422) Unprocessable Entity.

 

Please let me know where I am doing wrong or what missing in my code.

 

Thanks in advance,

Jyoti  


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]