0

“回复将直接发布到应用程序 URL。一旦发布,应用程序将需要从该信息中获取状态代码和消息 ID 以确定 SMS 传递的结果。”

基本上,我向 API 发送一个 http 请求以发送文本消息,并且该网站进一步将传递状态发送到我给他们的另一个 URL。现在我想使用 http 接收发送到我的应用程序的数据我如何在 asp.net 中做到这一点

编辑部分

 NameValueCollection pColl = Request.Params;

    // Iterate through the collection and add
    // each key to the string variable.
    for (int i = 0; i <= pColl.Count - 1; i++)
    {
        paramInfo += "Key: " + pColl.GetKey(i) + "<br />";



        // Create a string array that contains
        // the values associated with each key.
        string[]pValues = pColl.GetValues(i);


        // Iterate through the array and add
        // each value to the string variable.
        for (int j = 0; j <= pValues.Length - 1; j++)
        {

            paramInfo += "Value:" + pValues[j] + "<br /><br />";

        }
    }
Log(add, paramInfo);

上面的代码为我生成以下响应:

Key: result<br />Value:-5<br /><br />Key: transactionid<br        />Value:2a8b0559d2a6d96ff2250c5339356293<br /><br />Key: notification<br />Value:msgresult<br /><br />Key: messageid<br />Value:My test message.<br /><br />Key: botkey<br />Value:123456<br /><br />Key: ALL_HTTP<br />Value:HTTP_CONNECTION:keep-alive
HTTP_CONTENT_LENGTH:120
HTTP_CONTENT_TYPE:application/x-www-form-urlencoded
HTTP_ACCEPT:text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
HTTP_HOST:abcdef
HTTP_USER_AGENT:Java/1.6.0_21
HTTP_TRANSACTIONID:2a8b0559d2a6d96ff2250c5339356293
HTTP_MESSAGEID:95a8e9c37b9e449fe47e7d3acdd6f6e5
br /><br />Key: ALL_RAW<br />

如果 Key 的值是-5,我需要从整个响应中得到什么:结果

4

2 回答 2

3

您的服务提供商所说的是,他们会调用您的页面向您的页面发送数据(很可能是 POST)。

默认情况下,通过 http 调用 Asp.net 页面。

您可以接收如下参数:

protected void Page_Load(object sender, EventArgs e)
{
    var param1 = Request.Form["paramName"];
}

我确信您的服务提供商必须提供他们将发布的参数名称。

编辑: 您的编辑使它更容易。您需要的result已经是Request.Params.

你可以使用它

var result = Request.Params["result"];

或者更简单

var result = Request["result"];

注意:Request.Params在第一次调用时使用成本很高,因为它NameValueCollection通过添加来自 QueryString、Form、Cookie 和 ServerVariables 的参数来构建。

于 2013-01-18T08:56:53.183 回答
0

然后你可以去 httpwebrequest 和 httpwebresponse 如下

 HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create("http://Smsprovider");
 HttpWebResponse myResp = (HttpWebResponse)myReq.GetResponse();

然后您可以使用 myResp.StatusCode 类似的方式查看传递报告,例如,如果消息已传递,则 myResp.StatusCode 将等于 OK,您可以看到许多类似 http://msdn.microsoft.com/en-的属性我们/图书馆/system.net.httpwebresponse.aspx

于 2013-01-18T08:59:11.493 回答