PDA

View Full Version : Help with Socket/Parse/string please


BoBzY
02-17-2012, 16:38
Hello,

Currently using socket to download a page, and I need a way to remove the 'header'

Here the data received

HTTP/1.1 200 OK
Date: Fri, 17 Feb 2012 21:09:22 GMT
Server: Apache
P3P: policyref="/w3c/p3p.xml" CP="IDC DSP COR CURa ADMa OUR IND PHY ONL COM STA"
Connection: close
Content-Type: application/xml; charset=utf-8

<?xml version="1.0" encoding="utf-8"?>
etc...


All these datas are in the same string (called receiveData)

How to do to only get :


<?xml version="1.0" encoding="utf-8"?>
etc.


Already tried Regex, but pretty sure I did something wrong, I deleted the whole code, any idea?

Thanks to all

BoBzY
02-17-2012, 17:02
Found!


decl String:regex[40];
Format(regex, sizeof(regex), "(<\\?xml.*)");
new Handle:regex_compile = CompileRegex(regex);
if (MatchRegex(regex_compile, receiveData) > 0)
{
new String:buffer[2056];

GetRegexSubString(regex_compile, 1, buffer, sizeof(buffer));
PrintToServer("Buffer: %s", buffer);
}

Impact123
02-17-2012, 17:06
Im pretty shure there's a better way, but maybe you could use SplitString (http://docs.sourcemod.net/api/index.php?fastload=show&id=631&).

Edit: Nah, too late.

Yours sincerely
Impact

BoBzY
02-17-2012, 17:08
Im pretty shure there's a better way, but maybe you could use SplitString (http://docs.sourcemod.net/api/index.php?fastload=show&id=631&).

Edit: Nah, too late.

Yours sincerely
Impact


Oh didnt tested it ^^

But mine works fine

asherkin
02-17-2012, 19:38
You should split it at the first instance of \r\n, that's the terminator for the headers.

BoBzY
02-18-2012, 09:27
You should split it at the first instance of \r\n, that's the terminator for the headers.

Any example, please?