2015-04-24 6 views
0

Я получаю ниже ответ от веб-запроса, и я хочу извлечь данные из строки ниже, может ли кто-нибудь помочь мне, как я могу это сделать.Как извлечь значения из HTTP-ответа

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 <[email protected]>"], ["To", "[email protected]"], ["X-Mailgun-Track", "true"], ["X-Mailgun-Track-Clicks", "true"], ["X-Mailgun-Track-Opens", "true"], ["Message-Id", "<[email protected]>"], ["X-Mailgun-Sid", "WyIyZTY1OCIsICJtYW5vamt1bWFyLnNvbmlAZS16ZXN0LmluIiwgIjE4NmIzIl0="], ["Date", "Fri, 24 Apr 2015 04:49:58 +0000"], ["Sender", "[email protected]"], ["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

Вы можете подготовить значение заголовков из HttpRequest, как показано ниже.

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

IEnumerable HeaderValues ​​= req.Headers.GetValues ​​("Received"); var result = headerValues.FirstOrDefault(); Значение throw не может быть нулевым. исключение. Можете ли вы plesae дать мне знать, что должно быть paramenter_name в моем случае. Спасибо – ManojSoni

+0

вы можете передать любой ключ в заголовке. например, если вы хотите прочитать тему, то она должна быть IEnumerable headerValues ​​= req.Headers.GetValues ​​(«Subject»); var result = headerValues.FirstOrDefault(); – Rad

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