2015-05-18 6 views
0

На странице this url есть описание способа вызова tempoplugin с использованием сообщения. Для того, чтобы достичь этого, я создал следующие строки:Как добавить метод учетной записи для tempoplugin с сообщением в C#

enter image description here

также создал следующий код для размещения данных:

public static string HTTP_POST(string Url, string Data, string userName = "", string password = "") 
    { 

     string Out = String.Empty; 
     HttpWebRequest req = (HttpWebRequest)WebRequest.Create(Url); 
     try 
     { 
      if (userName != null && password != null) 
      { 
       req.ContentType = "application/json"; 
       req.Method = "POST"; 
       req.ProtocolVersion = HttpVersion.Version11; 

       string base64Credentials = GetEncodedCredentials(userName, password); 
       req.Headers.Add("Authorization", "Basic " + base64Credentials); 
      } 

      req.Timeout = 100000; 
      byte[] sentData = Encoding.UTF8.GetBytes(Data); 
      req.ContentLength = sentData.Length; 
      using (System.IO.Stream sendStream = req.GetRequestStream()) 
      { 
       sendStream.Write(sentData, 0, sentData.Length); 
       sendStream.Close(); 
      } 
      HttpWebResponse res = (HttpWebResponse)req.GetResponse(); 
      System.IO.Stream ReceiveStream = res.GetResponseStream(); 
      using (System.IO.StreamReader sr = new System.IO.StreamReader(ReceiveStream, Encoding.UTF8)) 
      { 
       Char[] read = new Char[256]; 
       int count = sr.Read(read, 0, 256); 

       while (count > 0) 
       { 
        String str = new String(read, 0, count); 
        Out += str; 
        count = sr.Read(read, 0, 256); 
       } 
      } 
     } 
     catch (ArgumentException ex) 
     { 
      Out = string.Format("HTTP_ERROR :: The second HttpWebRequest object has raised an Argument Exception as 'Connection' Property is set to 'Close' :: {0}", ex.Message); 
     } 
     catch (WebException ex) 
     { 
      Out = string.Format("HTTP_ERROR :: WebException raised! :: {0}", ex.Message); 
     } 
     catch (Exception ex) 
     { 
      Out = string.Format("HTTP_ERROR :: Exception raised! :: {0}", ex.Message); 
     } 

     return Out; 
    } 

Но все-таки я получаю ответ «Удаленный сервер возвратил ошибку: (404) Не обнаружена". Кто-нибудь знает, что я пропустил?

ответ

0

У меня есть решение. Проблема заключалась в разрешении на Джиру. После двойной проверки с админами мой код работал отлично.

 Смежные вопросы

  • Нет связанных вопросов^_^