Exemplo n.º 1
0
        public static CBResponse callJson(string myUrl,string httpMethod,JObject parameters) {

            try { 
            
                parameters.Add("sdk","C#");
            
            }catch(JsonException e){


                throw new JsonException(e.Message);
            }

            string parames = parameters.ToString();

            
            Uri url = null;

            try {
            
            url = new Uri(myUrl);
            
            }catch(UriFormatException e){

                throw new UriFormatException(e.Message);

            }

         
            HttpWebRequest r =(HttpWebRequest) System.Net.WebRequest.Create(url);
            r.Timeout = 10000;
            r.Method = httpMethod;
            r.UserAgent = "Mozilla/5.0 (Windows NT 6.1; rv:26.0) Gecko/20100101 Firefox/26.0";
            r.ContentType = "application/json";
           Stream dos = null;
           string respMsg = null;
           int respCode = 0;
           string inputString = null;
           string sid = null;

           try
           {

               WebResponse resp = null;
               resp = r.GetResponse();
               dos = resp.GetResponseStream();
               dos.Flush();
               dos.Close();
               StreamReader rdr = new StreamReader(dos);
               // string feedback = rdr.ReadToEnd();
               //respCode
               //respMsg
               if (respCode != 200)
               {

                   string error = "";
                   CBResponse res = new CBResponse(respMsg, respMsg, respCode, sid);
                   res.setError(error);
                   return res;
               }

               inputString = rdr.ReadToEnd();

           }catch(IOException e){

               CBResponse resp = new CBResponse(respMsg,respMsg,respCode,sid);
               return resp;
           }

           CBResponse respo = new CBResponse(respMsg,respMsg,respCode,sid);
           return respo;
        }
Exemplo n.º 2
0
        public static CBResponse postFormData(string myurl,string httpMethod, JObject parames, Stream inputstream) {

            Uri url = null;
            try {
                url = new Uri(myurl);
            
            
            }catch(IOException e){

                throw new IOException(e.Message);
            }
            HttpWebRequest req = (HttpWebRequest)System.Net.WebRequest.Create(url);
            req.Method = httpMethod;
            req.UserAgent = "Mozilla/5.0 (Windows NT 6.1; rv:26.0) Gecko/20100101 Firefox/26.0";
            req.ContentType = "multipart/form-data; boundary=" + "boundary"; //boundary;
            HttpWebResponse resp = null;
            resp = (HttpWebResponse)req.GetResponse();
             dos = resp.GetResponseStream();
             setParameter("key",CloudApp.AppKey);
             setParameter("fileObj",parames.ToString());
             setParameter("sdk","java");
             setFile("fileToUpload","blob",inputstream);
             Stream stream = post();
            int code = int.Parse(resp.StatusCode.ToString());
            string msg = resp.StatusDescription;
             string respon = inputStreamToString(stream);
             CBResponse ress = new CBResponse(respon, msg, code, null);
             return ress;
        }