AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   SteamTools (https://forums.alliedmods.net/forumdisplay.php?f=147)
-   -   Need help with http download (https://forums.alliedmods.net/showthread.php?t=221637)

Tentacle Master 07-24-2013 13:36

Need help with http download
 
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.

asherkin 07-24-2013 16:06

Re: Need help with http download
 
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.

Tentacle Master 07-24-2013 17:00

Re: Need help with http download
 
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.

asherkin 07-24-2013 17:15

Re: Need help with http download
 
Please provide your code.

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

Tentacle Master 07-26-2013 21:34

Re: Need help with http download
 
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;
}


asherkin 07-26-2013 22:01

Re: Need help with http download
 
Make sure the server is sending proper headers to block caching, it's very aggressive about following the spec.

Tentacle Master 07-26-2013 22:28

Re: Need help with http download
 
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.

asherkin 07-26-2013 22:31

Re: Need help with http download
 
Quote:

Originally Posted by Tentacle Master (Post 1999621)
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");


Tentacle Master 07-28-2013 04:38

Re: Need help with http download
 
Ah thanks for that.
You helped us make this:

https://forums.alliedmods.net/showthread.php?t=221927


All times are GMT -4. The time now is 03:56.

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