Parse a raw HTTP Response in C# to get the Status Code -


is there simple way parse http response string such follows:

"http/1.1 200 ok\r\ncontent-length: 1433\r\ncontent-type: text/html\r\ncontent-location: http://server/iisstart.htm\r\nlast-modified: fri, 21 feb 2003 23:48:30 gmt\r\naccept-ranges: bytes\r\netag: \"09b60bc3dac21:1ca9\"\r\nserver: microsoft-iis/6.0\r\nx-po" 

i status code. not need turn in httpresponse object, acceptable parsing out status code. able parse httpstatuscode enum?

i using sockets based approach , cannot change way getting response. have string work with.

edit taking account "i using sockets based approach , cannot change way getting response. have string work with".

how about

  string response = "http/1.1 200 ok\r\ncontent-length: 1433\r\ncontent-type: text/html\r\ncontent-location: http://server/iisstart.htm\r\nlast-modified: fri, 21 feb 2003 23:48:30 gmt\r\naccept-ranges: bytes\r\netag: \"09b60bc3dac21:1ca9\"\r\nserver: microsoft-iis/6.0\r\nx-po";    string code = response.split(' ')[1];   // int code = int.parse(response.split(' ')[1]); 

i had suggested this:

  httpwebrequest webrequest =(httpwebrequest)webrequest.create("http://www.gooogle.com/");   webrequest.allowautoredirect = false;   httpwebresponse response = (httpwebresponse)webrequest.getresponse();   int statuscode = (int)response.statuscode) 

Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -