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

socket_* returns Bad Request


Post New Thread Reply   
 
Thread Tools Display Modes
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 01-22-2021 , 11:01   Re: socket_* returns Bad Request
Reply With Quote #11

You are formatting your http request incorrectly
__________________
Bugsy is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 01-22-2021 , 11:11   Re: socket_* returns Bad Request
Reply With Quote #12

Why don't you use MySQL?
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !

Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
LondoN
Senior Member
Join Date: Dec 2015
Location: Roman, Romania.
Old 01-22-2021 , 13:51   Re: socket_* returns Bad Request
Reply With Quote #13

https://www.csservers.ro/surse/windows_hlds_v2.8.sma

i think might this help you (look for getting winner dns socket and how it used)
__________________
LondoN is offline
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 01-22-2021 , 16:28   Re: socket_* returns Bad Request
Reply With Quote #14

Quote:
Originally Posted by Shadows Adi View Post
Thanks, but it doesn't solved it.

I thought I make a mistake somewhere, so I tried this code from a tutorial:
PHP Code:
// code... 
This code as well returns me Bad request, with same HTML error code.
https://forums.alliedmods.net/showthread.php?t=151401
The missing slash was the reason for 400. HTTP servers are picky bastards.
https://en.wikipedia.org/wiki/Hypert...Client_request

The example code gives me "301 Moved Permanently" followed by the new link to follow. This is expected since the server enforces SSL which is not supported by sockets by itself. This was not the case when the tutorial was written. Using curl is your best option in these cases.

Spoiler
__________________

Last edited by Black Rose; 01-22-2021 at 17:01.
Black Rose is offline
Shadows Adi
AlliedModders Donor
Join Date: Aug 2019
Location: Romania
Old 01-23-2021 , 04:08   Re: socket_* returns Bad Request
Reply With Quote #15

Quote:
Originally Posted by Black Rose View Post
The missing slash was the reason for 400. HTTP servers are picky bastards.
https://en.wikipedia.org/wiki/Hypert...Client_request

The example code gives me "301 Moved Permanently" followed by the new link to follow. This is expected since the server enforces SSL which is not supported by sockets by itself. This was not the case when the tutorial was written. Using curl is your best option in these cases.

Spoiler
Thank you all, I thought so it is from sockets module.
I will contiune my project using curl.
__________________


Accepting Paid Requests, contact PM.

MVP Of The Round View project on GITHUB / AlliedModders
CSGO REMAKE ~ CSGO MOD [STABLE + SOURCE CODE]
Shadows Adi is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 01-23-2021 , 16:28   Re: socket_* returns Bad Request
Reply With Quote #16

Here's a curl example that you may be able to use. I converted my VAC Ban Status plugin today.
PHP Code:

#include <amxmodx>
#include <curl>

public plugin_init() 
{
    
register_concmd"curltest" "CurlTest" );
}

public 
CurlTestid )
{
    new 
CURL:cURLHandle curl_easy_init();
    
    
curl_easy_setoptcURLHandle CURLOPT_URL "https://steamcommunity.com/profiles/76561197986765713?xml=1" );
    
    
curl_easy_setoptcURLHandle CURLOPT_WRITEFUNCTION "ResponseReceived" );
    
curl_easy_performcURLHandle "CurlCallback" 
}

public 
ResponseReceived( const szBuffer[] , iSize iNumMemb sd )
{    
    new 
iBannedPos strfindszBuffer "<vacBanned>" );
    new 
iSteamNamePos strfindszBuffer "<steamID><![CDATA[" );
    new 
iSteamNameEnd strfindszBuffer "]]></steamID>" );
    new 
iSteamID64 strfindszBuffer "<steamID64>" );
    new 
iSteamID64End strfindszBuffer "</steamID64>" );
    
    new 
szStatus];
    new 
szName32 ];
    new 
szSteamID6432 ];
    
    if ( 
iBannedPos != -)
    {
        
copyszStatus charsmaxszStatus ) , szBufferiBannedPos 11 ] );
        
copyszName iSteamNameEnd - ( iSteamNamePos 18 ) , szBufferiSteamNamePos 18 ] );
        
copyszSteamID64 iSteamID64End - ( iSteamID64 11 ) , szBufferiSteamID64 11 ] );
        
server_print"VAC Banned=%s Name=|%s| Steam64=|%s|" szStatus szName szSteamID64 );
    }

    return ( 
iSize iNumMemb );
}

public 
CurlCallbackCURL:cURLHandle CURLcode:code )
{
    
curl_easy_cleanupcURLHandle );

__________________

Last edited by Bugsy; 01-24-2021 at 11:18.
Bugsy is offline
JocAnis
Veteran Member
Join Date: Jun 2010
Old 01-23-2021 , 17:17   Re: socket_* returns Bad Request
Reply With Quote #17

@bugsy, thanks for that code, its helpful!
Just a side note, isnt a 'CURLOPT_BUFFERSIZE' better to add there?

Code:
3) Always define the CURLOPT_BUFFERSIZE option, 
if you use the WRITEFUNCTION callback, specify a buffer size of no more than 1024 as a parameter, 
otherwise you risk getting stack errors, possibly even hanging the server. 
If you get stack errors when using other callbacks, then you can define in the plugin #pragma dynamic 30000
__________________
KZ Public Autocup - PrimeKZ

My blog: http://primekz.xyz (in progress...) - not active (dec 2022)

Last edited by JocAnis; 01-23-2021 at 17:18.
JocAnis is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 01-23-2021 , 17:59   Re: socket_* returns Bad Request
Reply With Quote #18

I missed that option as the documentation for curl is garbage. I struggled to find an example for something as simple as how to retrieve the incoming HTTP response packet. The above code is around an hour of trial and error and a ton of googling. This page was a good resource: https://curl.se/libcurl/c/

By default for this purpose it is large enough, but for those using this for other purposes should use it. I tried changing the value but no matter what value is set, the callback only gets triggered once, so I'm not sure about how to get a larger amount of data. I would expect it to keep getting fired until all data is received. I'm sure I'm just missing something as I have no curl experience.

https://curl.se/libcurl/c/CURLOPT_BUFFERSIZE.html
Code:
Pass a long specifying your preferred size (in bytes) for the receive buffer in libcurl. The main point of this would be that the write callback gets called more often and with smaller chunks. Secondly, for some protocols, there's a benefit of having a larger buffer for performance.

This is just treated as a request, not an order. You cannot be guaranteed to actually get the given size.

This buffer size is by default CURL_MAX_WRITE_SIZE (16kB). The maximum buffer size allowed to be set is CURL_MAX_READ_SIZE (512kB). The minimum buffer size allowed to be set is 1024.
__________________

Last edited by Bugsy; 01-23-2021 at 18:13.
Bugsy is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 01-23-2021 , 23:12   Re: socket_* returns Bad Request
Reply With Quote #19

Using this page for reference, it looks like the missing piece was returning a value in the write function. The below retrieves this thread, with the write function being called multiple times.

PHP Code:
#include <amxmodx>
#include <curl>

new CURL:cURLHandle;
new 
g_File;

public 
plugin_init() 
{
    
register_concmd"curltest" "CurlTest" );
}

public 
CurlTestid )
{
    
g_File fopen"curl_test.html" "wt" );
    
    
cURLHandle curl_easy_init();
    
    
curl_easy_setoptcURLHandle CURLOPT_URL "https://forums.alliedmods.net/showthread.php?t=330083" );
    
curl_easy_setoptcURLHandle CURLOPT_BUFFERSIZE 1024 );
    
curl_easy_setoptcURLHandle CURLOPT_WRITEFUNCTION "ResponseReceived" );
    
    
curl_easy_performcURLHandle "CurlCallback" );
}

public 
ResponseReceived( const szBuffer[] , iSize iNumMemb sd )
{    
    
fputsg_File szBuffer );
    
    return ( 
iSize iNumMemb );
}

public 
CurlCallbackCURL:cURLHandle CURLcode:code )
{
    
fcloseg_File );
    
    
curl_easy_cleanupcURLHandle );

__________________

Last edited by Bugsy; 01-23-2021 at 23:32.
Bugsy 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:07.


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