Vice City: Multiplayer

Server Development => Scripting and Server Management => Script and Content Requests => Topic started by: KrOoB_ on Aug 31, 2020, 01:10 PM

Title: Socket Bad Request
Post by: KrOoB_ on Aug 31, 2020, 01:10 PM
links are working also no problem in index but it's getting error while requesting why?
(https://i.imgur.com/QYaMshE.png)
(https://i.imgur.com/pchgjm0.png)
Title: Re: Socket Bad Request
Post by: Xmair on Aug 31, 2020, 01:36 PM
What's `acikka`? As far as I know, it's not an accept method. Give this a read: https://developer.mozilla.org/en-US/docs/Web/HTTP/Content_negotiation/List_of_default_Accept_values

TLDR: Accept: */*
Title: Re: Socket Bad Request
Post by: KrOoB_ on Aug 31, 2020, 01:56 PM
Quote from: Xmair on Aug 31, 2020, 01:36 PMWhat's `acikka`? As far as I know, it's not an accept method. Give this a read: https://developer.mozilla.org/en-US/docs/Web/HTTP/Content_negotiation/List_of_default_Accept_values

TLDR: Accept: */*
tried before still same
Title: Re: Socket Bad Request
Post by: KrOoB_ on Aug 31, 2020, 03:03 PM
(https://i.imgur.com/qmA07Q8.png)
i changed it like this but this time it says nothing
Title: Re: Socket Bad Request
Post by: Xmair on Sep 01, 2020, 09:28 AM
Try using the HTTP Requests (https://forum.vc-mp.org/?topic=7522.0) plugin by Luckshya.

local request = SqHTTP.GetRequest();
request.setURL("www.example.com");
request.setTag("myRequest");
request.sendGet();

function HTTP_OnResponse(tag, url, statusCode, response) {
switch(tag) {
case "myRequest": {
if (statusCode == 200) { // OK
print(response);
}
else { // Error
print(statusCode);
}
}
break;
}
}

Or if you want to stick to the official sockets plugin:
local sock = null;
local sockAddress = "www.example.com";

function setupSocket() {
sock = NewSocket("onSocketDataReceive");
sock.SetNewConnFunc("onSocketConnect");
sock.Connect(sockAddress, 80);
print(format("Connecting to %s...", sockAddress));
}

function onSocketDataReceive(data) {
print("Received data:");
print(data);
}

function onSocketConnect() {
print("Connection successful, sending data");

sock.Send("GET / HTTP/1.1\r\n");
sock.Send("Accept: */*\r\n");
sock.Send(format("Host: %s\r\n", sockAddress));
sock.Send("\r\n");
}

setupSocket();

Basically what you were missing was a "\r\n" in the end.
Title: Re: Socket Bad Request
Post by: habi on Sep 01, 2020, 02:24 PM
hi i was also working on this parallelly and finally got the answer.

host<-"vc-mp.org";
request<-"GET / HTTP/1.1\r\nHost: vc-mp.org\r\nAccept: */*\r\n\r\n";
function HTTP()
{
Socket<-NewSocket("abcd");
Socket.SetNewConnFunc("connF");
Socket.Connect(host,80);
}
function abcd(data)
{
print(data);
}
function connF(){
print("connF called");
print(request);
local q=Socket.Send(request);
}

And output
(https://i.imgur.com/nlMpdrV.png)
and
(https://i.imgur.com/OTqRs3r.png)

Notes:
1. The inbuilt print function is enough.
Socket<-NewSocket("print");2. This \r\n are very important. ( Using @"" is a bit confused. )
Title: Re: Socket Bad Request
Post by: KrOoB_ on Sep 02, 2020, 06:56 AM
Quote from: habi on Sep 01, 2020, 02:24 PMhi i was also working on this parallelly and finally got the answer.

host<-"vc-mp.org";
request<-"GET / HTTP/1.1\r\nHost: vc-mp.org\r\nAccept: */*\r\n\r\n";
function HTTP()
{
Socket<-NewSocket("abcd");
Socket.SetNewConnFunc("connF");
Socket.Connect(host,80);
}
function abcd(data)
{
print(data);
}
function connF(){
print("connF called");
print(request);
local q=Socket.Send(request);
}

And output
(https://i.imgur.com/nlMpdrV.png)
and
(https://i.imgur.com/OTqRs3r.png)

Notes:
1. The inbuilt print function is enough.
Socket<-NewSocket("print");2. This \r\n are very important. ( Using @"" is a bit confused. )
i just found a json plugin and i'll use it ( i recommend it )