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

Solved How to Read from TXT file?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
6Yukimuro9
Junior Member
Join Date: May 2019
Location: Serbia, Belgrade
Old 05-31-2019 , 08:16   How to Read from TXT file?
Reply With Quote #1

Hello, I have these variables:

path - path to .txt file
html_response - content of .txt file

I need to parse `path` to `html_response`, I tried many thing and Its not working

I believe its not so hard because I never did an AMXMODX but I'm familiar with PAWN because of SA-MP...

( In SA-MP there was simple fread native )

Last edited by 6Yukimuro9; 06-01-2019 at 17:24.
6Yukimuro9 is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 05-31-2019 , 08:33   Re: How to Read from TXT file?
Reply With Quote #2

If you simply want to load the contents of the file "path" in "html_response", you can easily do that by using the LoadFileForMe function.
__________________

Last edited by OciXCrom; 05-31-2019 at 08:33.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
6Yukimuro9
Junior Member
Join Date: May 2019
Location: Serbia, Belgrade
Old 05-31-2019 , 08:38   Re: How to Read from TXT file?
Reply With Quote #3

Quote:
Originally Posted by OciXCrom View Post
If you simply want to load the contents of the file "path" in "html_response", you can easily do that by using the LoadFileForMe function.
Code:
if (file_exists(path))
	{
		new response[1], length;
		LoadFileForMe(path, response, sizeof(response), length);
		server_print("Path = %s", path);
		server_print("Buffer = %s", response);
	}
Resulted

HTML Code:
Path = 160.2.52.234.txt
Buffer =
Always nothing is returned to buffer ( I checked file and it is single Y which is good )

EDIT:

Here, I tried this and same result...

Code:
public client_connectex(id, const name[], const ip[], reason[128])
{
	new client_ip[MAX_IP_LENGTH], path[MAX_IP_LENGTH + 16];
	get_user_ip(id, client_ip, sizeof(client_ip), 1);
	
	format(client_ip, sizeof(client_ip), "160.2.52.234"); // Random proxy IP for testing
	
	replace_string(proxy_url, url_size, "{IP}", client_ip, false);
	
	format(path, sizeof(path), "%s.txt", client_ip);
	
	HTTP_DownloadFile(proxy_url, path);
	
	if (file_exists(path))
	{
		new file = fopen(path, "r");
		new a[16];
		
		fgets(file, a, charsmax(a));
		server_print("%s", a);
		fclose(file);
	}
	return PLUGIN_CONTINUE;
}
...and issue was with HTTP_Download, I commented it and everything was OK.,..

Last edited by 6Yukimuro9; 05-31-2019 at 08:55.
6Yukimuro9 is offline
thEsp
BANNED
Join Date: Aug 2017
Old 05-31-2019 , 09:44   Re: How to Read from TXT file?
Reply With Quote #4

https://forums.alliedmods.net/showpo...93&postcount=5
thEsp is offline
6Yukimuro9
Junior Member
Join Date: May 2019
Location: Serbia, Belgrade
Old 05-31-2019 , 11:20   Re: How to Read from TXT file?
Reply With Quote #5

Quote:
Originally Posted by thEsp View Post
I know, please read what I wrote, probably every method I tried was working but problem was HTTP_Download
6Yukimuro9 is offline
thEsp
BANNED
Join Date: Aug 2017
Old 05-31-2019 , 14:36   Re: How to Read from TXT file?
Reply With Quote #6

Make buffer at least 2 characters long or more (Suppose first char is response, and as always the last one is '\n' which stands for newline), and sockets don't actually support HTTP-S.
thEsp is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 05-31-2019 , 22:43   Re: How to Read from TXT file?
Reply With Quote #7

Quote:
Originally Posted by thEsp View Post
as always the last one is '\n' which stands for newline
In what case is this true? It's not true regarding general strings in Pawn.
__________________
fysiks is offline
6Yukimuro9
Junior Member
Join Date: May 2019
Location: Serbia, Belgrade
Old 06-01-2019 , 17:23   Re: How to Read from TXT file?
Reply With Quote #8

Quote:
Originally Posted by thEsp View Post
Make buffer at least 2 characters long or more (Suppose first char is response, and as always the last one is '\n' which stands for newline), and sockets don't actually support HTTP-S.
I alredy made it work, anyway thx..
6Yukimuro9 is offline
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 06-08-2019 , 08:37   Re: How to Read from TXT file?
Reply With Quote #9

Quote:
Originally Posted by thEsp View Post
sockets don't actually support HTTP-S.
HTTPS is a protocol at a higher level than Sockets. Sockets can't even tell the difference.

I think the only thing that currently works with HTTPS is the cURL module.
__________________

Last edited by Black Rose; 06-08-2019 at 08:39.
Black Rose is offline
Reply



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:16.


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