如何从HTTP响应中提取值

时间:2015-04-24 05:15:40

标签: c# asp.net arrays asp.net-mvc-4 webrequest

我收到来自网络版请求的回复,我想从下面的字符串中提取数据,任何人都可以帮助我如何做到这一点。

message-headers[["Received", "by luna.mailgun.net with HTTP; Fri, 24 Apr 2015 04:49:58 +0000"], ["Mime-Version", "1.0"], ["Content-Type", ["text/html", {"charset": "ascii"}]], ["Subject", "Booking Confirmation :  2/99 Normanby Road, Kew,Australia"], ["From", "Digital Photography Inhouse <bookings@test.net.au>"], ["To", "manojkumar.soni@e-zest.in"], ["X-Mailgun-Track", "true"], ["X-Mailgun-Track-Clicks", "true"], ["X-Mailgun-Track-Opens", "true"], ["Message-Id", "<20150424044958.30315.17928@schedly.com.au>"], ["X-Mailgun-Sid", "WyIyZTY1OCIsICJtYW5vamt1bWFyLnNvbmlAZS16ZXN0LmluIiwgIjE4NmIzIl0="], ["Date", "Fri, 24 Apr 2015 04:49:58 +0000"], ["Sender", "bookings=manoj.net.au@test.com.au"], ["Content-Transfer-Encoding", ["quoted-printable", {}]]]

我正在阅读下面的值,请告诉我阅读此数据的最佳方法是什么。

public int insertData(HttpRequest req)
{
    if (req["Parameter_Name"] != null)
        parameter_Name = (string)req["Parameter_Name"];

    if (req["message-headers"] != null)
    {
        message_headers = (string)req["message-headers"];    
    }     
}

1 个答案:

答案 0 :(得分:1)

您可以从HttpRequest准备好标头的值,如下所示。

IEnumerable<string> headerValues = req.Headers.GetValues("Parameter_Name");
var result = headerValues.FirstOrDefault();