Socket Bad Request

Started by KrOoB_, Aug 31, 2020, 01:10 PM

Previous topic - Next topic

KrOoB_

links are working also no problem in index but it's getting error while requesting why?


Xmair

#1
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: */*

Credits to Boystang!

VU Full Member | VCDC 6 Coordinator & Scripter | EG A/D Contributor | Developer of VCCNR | Developer of KTB | Ex-Scripter of EAD

KrOoB_

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

KrOoB_


i changed it like this but this time it says nothing

Xmair

#4
Try using the HTTP Requests 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.

Credits to Boystang!

VU Full Member | VCDC 6 Coordinator & Scripter | EG A/D Contributor | Developer of VCCNR | Developer of KTB | Ex-Scripter of EAD

habi

#5
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

and


Notes:
1. The inbuilt print function is enough.
Socket<-NewSocket("print");2. This \r\n are very important. ( Using @"" is a bit confused. )

KrOoB_

#6
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

and


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 )