无法使用基于OpenShift REST的API的POST方法

时间:2014-11-20 13:45:24

标签: api openshift redhat

我正在尝试使用我在C#.net中开发的示例代码在OpenShift Red Hat环境中创建应用程序。

string url =string.Format("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\": [{"
                    + "\"cartridge\": \"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();          
        dataStream = response.GetResponseStream();            
        StreamReader reader = new StreamReader(dataStream);            
        string responseFromServer = reader.ReadToEnd();
        reader.Close();
        dataStream.Close();
        response.Close();

当我执行上面的代码时,我收到以下错误 - "远程服务器返回错误:(422)Unprocessable Entity。"在这下面的行 - " WebResponse response = request.GetResponse();" 请让我在哪里做错了。在此先感谢Jyoti

0 个答案:

没有答案