本人開發經驗不足,專案中要呼叫語音通知的介面,服務器會把通知結果通過回呼URL地址發給我,我要怎么來接收結果呢?我的思路是寫一個ashx頁面來接收服務器的通知結果。但是始終沒有頭緒要怎么來寫代碼,請大神指導一下,或者給一個案例參考。
下圖是服務器的通知結果推送請求:

ashx檔案代碼如下(想著先接收請求,列印到文本保存,已經部署到云服務器,測驗請求提示500錯誤,郁悶...):
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.IO;
using System.Linq;
using System.Text;
using System.Web;
namespace Voice_Report
{
/// <summary>
/// Handler 的摘要說明
/// </summary>
public class Handler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
NameValueCollection myHeader = new NameValueCollection();
int i;
string strKey;
string result;
myHeader = context.Request.Headers;
int total = myHeader.Count;
string strResult = "";
//獲取header里的引數的值
for (i = 1; i < total; i++)
{
strKey = myHeader.GetKey(i);
if (strKey == "number")
{
strResult += myHeader.Get(strKey);
}
if (strKey == "state")
{
strResult += myHeader.Get(strKey) + "\r\n";
}
}
//獲取請求的body的值
Stream resStream = HttpContext.Current.Request.InputStream;
StreamReader sr = new StreamReader(resStream, System.Text.Encoding.Default);
string requestXml = sr.ReadToEnd();
result = strResult;
//寫入txt檔案
string FullFileName = @"D:\log_20200115.txt";
StreamWriter sw = new StreamWriter(FullFileName, true, Encoding.Default);
sw.Write("測驗");
//sw.Write(result.ToString());
sw.Write("\r\n" + "寫入完成");
sw.Close();
}
public bool IsReusable
{
get
{
return false;
}
}
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/74838.html
標籤:ASP.NET
