Raised This Month: $32 Target: $400
 8% 

Need help with http download


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Tentacle Master
Member
Join Date: Jan 2012
Old 07-24-2013 , 13:36   Need help with http download
Reply With Quote #1

I have a json file I need to download to my server or read and put it into a string from a remote website every 15 secs.
I'd probably use the Jamison Extension to read the json file/string once I have it.

My original plan was to use cURL to download the file but my GSP wont update VC++ so that it runs correctly. My thought now is to use Steamtools rather than Socket. I think I have an idea of what the code I want is to look like but I need to know where SteamTools downloads the file in the file system.

Or if anyone else has any better ways of doing this, I'm all ears.
__________________
Maximum Online Gaming: Multi Tanks Maximum Spawn Servers (MTMS) Head Admin / Programmer

Plugins:
Automatic Main Menu Opener -public ||| My Little Pony Models Pack -public ||| No One Left4Dead -private ||| Fortspawn 2 -private

Last edited by Tentacle Master; 07-24-2013 at 13:39.
Tentacle Master is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 07-24-2013 , 16:06   Re: Need help with http download
Reply With Quote #2

Look at the example here.

Steam_WriteHTTPResponseBody is based in the server's current directory, use SM's BuildPath native to create a path to the SM data folder if you need a sane temporary location - if whatever you're parsing it with can just take a string of data, don't write it out at all and use Steam_GetHTTPResponseBodyData instead.
__________________
asherkin is offline
Tentacle Master
Member
Join Date: Jan 2012
Old 07-24-2013 , 17:00   Re: Need help with http download
Reply With Quote #3

Thanks asherkin. I found a store plugin that used Steam_GetHTTPResponseBodyData So i tried that out. It downloaded the json file into a string and then (because I'm lazy this afternoon) outputted the result to the ErrorLog. I only got the first 1024 chars outputted though. Is that a limitation with SteamTools or the Error handling with the log? The length of the json string is around 8000 chars.
__________________
Maximum Online Gaming: Multi Tanks Maximum Spawn Servers (MTMS) Head Admin / Programmer

Plugins:
Automatic Main Menu Opener -public ||| My Little Pony Models Pack -public ||| No One Left4Dead -private ||| Fortspawn 2 -private

Last edited by Tentacle Master; 07-24-2013 at 17:01.
Tentacle Master is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 07-24-2013 , 17:15   Re: Need help with http download
Reply With Quote #4

Please provide your code.

EDIT: Yeah, it's a limitation of LogError.
__________________

Last edited by asherkin; 07-24-2013 at 17:17.
asherkin is offline
Tentacle Master
Member
Join Date: Jan 2012
Old 07-26-2013 , 21:34   Re: Need help with http download
Reply With Quote #5

So I am calling this function every 15 secs because that how often the file im grabbing gets updated. I can pull it up and refresh it in a browser and watch the changes.

It is indeed outputting info to the Error Log every 15 secs. On rare occasion it errors. The problem is that it is not downloading the updated file. Its like it downloading the cache of the file or something. Only about 3 times during a 30 min period did it download the current file.

Any ideas?

Code:
public UpdateData()
{
    if (g_HTTPRequest != INVALID_HTTP_HANDLE) g_HTTPRequest = INVALID_HTTP_HANDLE;
    g_HTTPRequest = Steam_CreateHTTPRequest(HTTPMethod_GET, "http://www.fakeurl.com/static/api/data.txt");
    Steam_SendHTTPRequest(g_HTTPRequest, OnDownloadComplete);
}

public OnDownloadComplete(HTTPRequestHandle:HTTPRequest, bool:requestSuccessful, HTTPStatusCode:statusCode)
{
    if (HTTPRequest != g_HTTPRequest || !requestSuccessful || statusCode != HTTPStatusCode_OK)
    {
        LogError("[DEBUG] Something went wrong with the HTTP download");
        return;
    }
    decl String:data[6000];
    
    Steam_GetHTTPResponseBodyData(g_HTTPRequest, data, sizeof(data));
    LogError("[DEBUG] %s", data);
    Steam_ReleaseHTTPRequest(g_HTTPRequest);
    g_HTTPRequest = INVALID_HTTP_HANDLE;
}
__________________
Maximum Online Gaming: Multi Tanks Maximum Spawn Servers (MTMS) Head Admin / Programmer

Plugins:
Automatic Main Menu Opener -public ||| My Little Pony Models Pack -public ||| No One Left4Dead -private ||| Fortspawn 2 -private

Last edited by Tentacle Master; 07-26-2013 at 21:41.
Tentacle Master is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 07-26-2013 , 22:01   Re: Need help with http download
Reply With Quote #6

Make sure the server is sending proper headers to block caching, it's very aggressive about following the spec.
__________________
asherkin is offline
Tentacle Master
Member
Join Date: Jan 2012
Old 07-26-2013 , 22:28   Re: Need help with http download
Reply With Quote #7

yay another fun conversation with my GSP. I can't win.

Yeah for about 7-15 minutes it downloads the right info then for another 7-15 mins it downloads a cached version, rinse, repeat.

If they refuse to help me I may just have 10 of the same file generated and numbered then download them in sequence. That's so ghetto.
__________________
Maximum Online Gaming: Multi Tanks Maximum Spawn Servers (MTMS) Head Admin / Programmer

Plugins:
Automatic Main Menu Opener -public ||| My Little Pony Models Pack -public ||| No One Left4Dead -private ||| Fortspawn 2 -private
Tentacle Master is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 07-26-2013 , 22:31   Re: Need help with http download
Reply With Quote #8

Quote:
Originally Posted by Tentacle Master View Post
yay another fun conversation with my GSP. I can't win.

Yeah for about 7-15 minutes it downloads the right info then for another 7-15 mins it downloads a cached version, rinse, repeat.

If they refuse to help me I may just have 10 of the same file generated and numbered then download them in sequence. That's so ghetto.
Call these two functions before sending the HTTP request:
Code:
Steam_SetHTTPRequestHeaderValue(hRequest, "Pragma", "no-cache");
Steam_SetHTTPRequestHeaderValue(hRequest, "Cache-Control", "no-cache");
__________________
asherkin is offline
Tentacle Master
Member
Join Date: Jan 2012
Old 07-28-2013 , 04:38   Re: Need help with http download
Reply With Quote #9

Ah thanks for that.
You helped us make this:

https://forums.alliedmods.net/showthread.php?t=221927
__________________
Maximum Online Gaming: Multi Tanks Maximum Spawn Servers (MTMS) Head Admin / Programmer

Plugins:
Automatic Main Menu Opener -public ||| My Little Pony Models Pack -public ||| No One Left4Dead -private ||| Fortspawn 2 -private
Tentacle Master is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 13:37.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode