Vice City: Multiplayer

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

Title: Socket Bad Request
Post by: KrOoB_ on August 31st, 2020, 02: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 August 31st, 2020, 02: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:
Code: [Select]
Accept: */*
Title: Re: Socket Bad Request
Post by: KrOoB_ on August 31st, 2020, 02:56 PM
Quote from Xmair on August 31st, 2020, 02: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:
Code: [Select]
Accept: */*
tried before still same
Title: Re: Socket Bad Request
Post by: KrOoB_ on August 31st, 2020, 04: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 September 1st, 2020, 10:28 AM
Try using the HTTP Requests(https://forum.vc-mp.org/?topic=7522.0) plugin by Luckshya.

Code: [Select]
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:
Code: [Select]
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 September 1st, 2020, 03:24 PM
hi i was also working on this parallelly and finally got the answer.

Code: [Select]
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.
Code: [Select]
Socket<-NewSocket("print");
2. This \r\n are very important. ( Using @"" is a bit confused. )
Title: Re: Socket Bad Request
Post by: KrOoB_ on September 2nd, 2020, 07:56 AM
Quote from habi on September 1st, 2020, 03:24 PM
hi i was also working on this parallelly and finally got the answer.

Code: [Select]
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.
Code: [Select]
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 )