Raised This Month: $ Target: $400
 0% 

Solved getting data from get request not work


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
newone123
Junior Member
Join Date: May 2021
Old 05-13-2021 , 01:41   getting data from get request not work
Reply With Quote #1

FIXED BY CURL
1. AmxxCurl
2. LINUX: download and move curl_amxx_i386.so to amxmodx/modules (server)
3. write curl_amxx in amxmodx/configs/modlues.ini (server)
4. put the includes: curl.inc and curl_consts.inc in amxmodx\scripting\include (server and compiler)
FIX
Code:
#include <amxmodx>
#include <amxmisc>
#include <curl>

#define CURL_BUFFER_SIZE 512

public plugin_init()
{
   register_plugin("curl http get", "1.0", "Polarhigh")
   
   new data[1]
   data[0] = fopen("addons/amxmodx/alliedmods_main_page.html", "wb")
   server_print("curl start")
   
   new CURL:curl = curl_easy_init()
   curl_easy_setopt(curl, CURLOPT_BUFFERSIZE, CURL_BUFFER_SIZE)
   curl_easy_setopt(curl, CURLOPT_URL, "https://forums.alliedmods.net")
   curl_easy_setopt(curl, CURLOPT_WRITEDATA, data[0])
   curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, "write")
   curl_easy_perform(curl, "complite", data, sizeof(data))
}

public write(data[], size, nmemb, file)
{
   new actual_size = size * nmemb;
   
   fwrite_blocks(file, data, actual_size, BLOCK_CHAR)
   
   return actual_size
}

public complite(CURL:curl, CURLcode:code, data[])
{
  if(code == CURLE_WRITE_ERROR)
     server_print("transfer aborted")
  else
     server_print("curl complete")
  
  fclose(data[0])
  curl_easy_cleanup(curl)
}
The Problem
code
Code:
#include <amxmodx>
#include <sockets>

#define READ_TASK 1
#define TOPIC "/forumdisplay.php?f=11"
#define HOST "forums.alliedmods.net"
new g_Socket
new g_Data[1001]

public plugin_init() {
	register_clcmd("say !newz", "get_news")
}

public get_news() {
	new error 
	g_Socket = socket_open(HOST, 80, SOCKET_TCP, error)
	if(error == 0) {
		new request[501]
		formatex(request, charsmax(request), "GET %s HTTP/1.1 ^n Host: %s ^n Connection: close", TOPIC, HOST)
		socket_send2(g_Socket, request, charsmax(request))
		set_task(0.1 , "read_socket", READ_TASK, _, _, "b")
		set_task(30.0 , "close_socket")
	} else client_print(0, print_chat, "error")
}

public read_socket() {
	if(socket_is_readable(g_Socket)) {
		new countByte 
		countByte = socket_recv(g_Socket, g_Data, charsmax(g_Data))
		if(countByte > 0) {
			remove_task(READ_TASK)
		}
	}
}

public close_socket() {
	socket_close(g_Socket)
	new path[] = "addons/j/data.txt"
	new file = fopen(path,"w")
	if(file) fputs(file, g_Data)
	fclose(file)
}
result
Code:
HTTP/1.1 400 Bad Request

Server: cloudflare

Date: Thu, 13 May 2021 05:39:43 GMT

Content-Type: text/html

Content-Length: 155

Connection: close

CF-RAY: -



<html>

<head><title>400 Bad Request</title></head>

<body>

<center><h1>400 Bad Request</h1></center>

<hr><center>cloudflare</center>

</body>

</html>

Last edited by newone123; 05-13-2021 at 06:42.
newone123 is offline
 


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 02:38.


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