Jump to content
Oz Linden

llHTTPRequest changes

Recommended Posts

I know the last reponse was back in October however it seemed relevent to post this in here. I'm trying to pull stats from a shoutcast v2 stream and while it gives me my floating text, it's not displaying the relevant info(the song title). I can confirm that my IP, while being v2, gives me stats from 7.html

The script I'm working with:

string stream = "http://198.15.88.42:8042"; 
key kSentRequest;

default
{
    state_entry()
    {   
        kSentRequest=llHTTPRequest(stream + "/7", [HTTP_USER_AGENT, "LSL_Script (Mozilla Compatible)"],"");
    }
    
    http_response (key kRecRequest, integer intStatus, list lstMeta, string strBody)
    {
        if (kRecRequest == kSentRequest)
        {   
            list html = llParseString2List(strBody,["<body>", "</body>"],[]);
            string info = (llList2String(html,6));
            
            list status = llCSV2List(info);
            llSetText ("Now playing on Aristide Radio \n"+llList2String(status,6),<1,1,1>,1);
            kSentRequest = NULL_KEY;
        }
    }
}

 

Share this post


Link to post
Share on other sites
1 hour ago, Laufiair Hexicola said:

Your http request is fine - you're not parsing the response correctly.

What's coming back from the server is:


<html><body>1,1,10,50,1,96,Abney Park - Under the Radar</body></html>

so to get the song title, you need:


 list result = llParseString2List(strBody,["<html><body>", ",", "</body></html>"],[]);
 string songtitle = llList2String(result,6);

 

 

  • Like 1

Share this post


Link to post
Share on other sites

Hello Oz, I changed the list and string around and it didn't seem to do anything. I did try to see if I could see the entire string and that didn't show anything either.

key http_request_id;
 
default
{
    state_entry()
    {
        http_request_id = llHTTPRequest("http://198.15.88.42:8042/7.html", [HTTP_USER_AGENT, "LSL_Script_(Mozilla Compatible)"],"");
    }
 
    http_response(key request_id, integer status, list metadata, string body)
    {
        if (request_id == http_request_id)
        {
            list result = llParseString2List(body,["<html><body>", ", ", "</body></html>"],[]);
            string songtitle = llList2String(result,6);
//            list status = llCSV2List(songtitle);
            llSetText ("Now playing on Aristide Radio \n"+(string)songtitle,<1,1,1>,1);
        }
    }
}

 

Share this post


Link to post
Share on other sites

You used

["<html><body>", ", ", "</body></html>"]

but it should be 

["<html><body>", ",", "</body></html>"]

note that there is no space following the comma that's inside quotes. That list specifies the parts of the string to be removed and treated as separators when constructing the list; since there are no spaces following the commas in the string returned by the shoutcast service, you get a list containing a single string that includes everything but the tags.

  • Thanks 2

Share this post


Link to post
Share on other sites
12 hours ago, Laufiair Hexicola said:

I did try to see if I could see the entire string and that didn't show anything either.

You also want to avoid the word "Script" in the header. Some servers seem to skip requests with such lettering.

[HTTP_USER_AGENT, "LSL (Mozilla Compatible)"]

Should do the trick.

Share this post


Link to post
Share on other sites
3 hours ago, arton Rotaru said:

You also want to avoid the word "Script" in the header. Some servers seem to skip requests with such lettering.


[HTTP_USER_AGENT, "LSL (Mozilla Compatible)"]

Should do the trick.

That didn't do anything - even put an underscore between LSL and Mozilla and no change. It's displaying the text, but not the song name.

Share this post


Link to post
Share on other sites
1 minute ago, Laufiair Hexicola said:

That didn't do anything - even put an underscore between LSL and Mozilla and no change. It's displaying the text, but not the song name.

Did you follow Oz's advice? You have an extra space after one of your quoted commas. He said above:

You used

["<html><body>", ", ", "</body></html>"]

but it should be 

["<html><body>", ",", "</body></html>"]

note that there is no space following the comma that's inside quotes. That list specifies the parts of the string to be removed and treated as separators when constructing the list; since there are no spaces following the commas in the string returned by the shoutcast service, you get a list containing a single string that includes everything but the tags.

Share this post


Link to post
Share on other sites
15 minutes ago, Laufiair Hexicola said:

not sure how I overlooked that one

Perhaps you didn't see the update because of how Oz replied. (The forum only notifies you of replies when you are "quoted".) It's all good!

  • Thanks 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...