欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

C#中調(diào)用Servlet示例

 更新時(shí)間:2015年05月23日 12:05:08   投稿:junjie  
這篇文章主要介紹了C#中調(diào)用Servlet示例,本文實(shí)現(xiàn)通用消息接口使用servlet作為服務(wù)器端服務(wù)接口,第三方應(yīng)用程序通過http post的方式調(diào)用servlet,實(shí)現(xiàn)與通用消息接口的調(diào)用連接,需要的朋友可以參考下

需求

通用消息接口使用servlet作為服務(wù)器端服務(wù)接口,第三方應(yīng)用程序通過http post的方式調(diào)用servlet,實(shí)現(xiàn)與通用消息接口的調(diào)用連接。
參數(shù)說明如下:
msgTitle:消息標(biāo)題,描述發(fā)送消息的標(biāo)題
serviceId:服務(wù)編號(hào),消息的服務(wù)編號(hào)
msgDesp:消息描述,消息的詳細(xì)內(nèi)容
msgURL:URL地址,消息中包含的 URL
上述4個(gè)參數(shù)的參數(shù)值可以為空,但參數(shù)必須提供。

調(diào)用示例

下面一段簡(jiǎn)單的html代碼,描述了如何通過網(wǎng)頁(yè)進(jìn)行調(diào)用通用消息接口的模式,供參考。

復(fù)制代碼 代碼如下:

<html><head><title>Sametime通用消息服務(wù)</title>
</head><body>
<formaction="http://stproxy.test.foton.com:9080/
fotonstbot/ServiceServlet" method="post">name="msgTitle" /><br />
服務(wù)編號(hào): <input type="text" id="serviceId" name="serviceId" /><br />
消息描述:  <input type="text" id="msgDesp" name="msgDesp" /><br />
URL:   <input type="text" id="msgUrl" name="msgUrl" /><br />
系統(tǒng)類型:   <input type="text" id="sysType" name="sysType" /><br />
目標(biāo)用戶:  <input type="text" id="targetuser" name="targetuser" style="width:500px;" /><br />
<input type="submit" value="Submit" />
</form>
</body></html>

C#調(diào)用示例

復(fù)制代碼 代碼如下:

/// <summary>
/// sametime
/// </summary>
/// <param name="bstrReceiver">sametime用戶</param>
/// <param name="bstrTitle">標(biāo)題</param>
/// <param name="lDelayTime">響應(yīng)時(shí)間</param>
/// <param name="bstrMsg">內(nèi)容</param>
public static void SendNotify(string bstrReceiver, string bstrTitle, int lDelayTime, string bstrMsg)
{
    string user="";
    try {
        String url = "http://stproxy.foton.com.cn:9081/fotonstbot/ServiceServlet";//html調(diào)用的地址              
        HttpWebRequest webrequest = (HttpWebRequest)WebRequest.Create(url);
        if(webrequest==null)
        {
            RecorderErrorRtx(bstrReceiver,bstrTitle,bstrMsg,"服務(wù)端異常",0);
            return;
        }
        webrequest.Method = "POST";
        webrequest.Timeout = lDelayTime;
        webrequest.ContentType = "application/x-www-form-urlencoded";
        byte[] bufferTitile = Encoding.GetEncoding("utf-8").GetBytes(bstrTitle);       
        string sbTitle = "";
        foreach (byte b in bufferTitile) sbTitle=sbTitle+(string.Format("%{0:X}", b));
        byte[] bufferContent = Encoding.GetEncoding("utf-8").GetBytes(bstrMsg);
        string sbContent = "";
        //UTF8注意轉(zhuǎn)碼
        foreach (byte b in bufferContent) sbContent=sbContent+(string.Format("%{0:X}", b));
        System.Collections.Hashtable pars=new System.Collections.Hashtable();
        pars.Add("msgTitle", sbTitle);
        pars.Add("serviceId", "");
        pars.Add("msgDesp",  sbContent);
        pars.Add("msgUrl", "");
        pars.Add("sysType", "QCTS");
        user="uid="+bstrReceiver+",cn=users,DC=FOTON;";
        pars.Add("targetuser", user);
        string buffer="";
        //發(fā)送POST數(shù)據(jù) 
        if (!(pars == null || pars.Count == 0))
        {

            foreach (string key in pars.Keys)
            {
                buffer=buffer+"&"+key+"="+pars[key].ToString();                
            }
            byte[] data = Encoding.UTF8.GetBytes(buffer);
            using (Stream stream = webrequest.GetRequestStream())
            {
                stream.Write(data, 0, data.Length);
            }
        }

        string[] values = webrequest.Headers.GetValues("Content-Type");
        WebResponse myResponse= webrequest.GetResponse();

        using(Stream resStream = myResponse.GetResponseStream())//得到回寫的流
        {
            StreamReader newReader = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8);
            string Content = newReader.ReadToEnd();        
            newReader.Close();
        }
        RecorderRtx(user,bstrTitle,bstrMsg,0);

    }

    catch(Exception ex)
    {
        RecorderErrorRtx(user,bstrTitle,bstrMsg,ex.Message,0); 
    }                                              
}

相關(guān)文章

最新評(píng)論