Closed david6228 closed 1 year ago
Hi @david6228 , I'm not familiar with Perl, but the /sql
endpoint accepts text, not JSON. Currently, if I understand it correctly, you are sending an { "data"=>"SELECT * FROM person WHERE age > 18" }
object as the body?
think you respose. I try post a text, but the error is same, may be the problem is that the post request must have a field as key.
my $ua = Mojo::UserAgent->new;
$ua->post_p("http://root:root@127.0.0.1:8000/sql" =>{ "content_type"=>"application/x-www-form-urlencoded","Accept"=>"application/json", "NS" => "test","DB" =>"test" } => form =>{ "data" => "SELECT * FROM person WHERE age > 18" } )
->then( sub ($tx) {
say $tx->result->body;
})->catch(sub ($err) {
warn "Connection error: $err";
})->wait;
{"code":400,"details":"Request problems detected","description":"There is a problem with your request. Refer to the documentation for further information.","information":"There was a problem with the database: Parse error on line 1 at character 0 when parsing 'data=SELECT+*+FROM+person+WHERE+age+%3E+18'"}
OK, I get the right post request way, think you again.
my $ua = Mojo::UserAgent->new;
$ua->post_p("http://root:root@127.0.0.1:8000/sql" =>{ "Accept"=>"application/json", "NS" => "test","DB" =>"test" } => "SELECT * FROM person WHERE age > 18" )
->then( sub ($tx) {
say $tx->result->body;
})->catch(sub ($err) {
warn "Connection error: $err";
})->wait;
[{"time":"41.03\x{00c2}μs","status":"OK","result":[]}]
Describe the bug
test perl useragent post request fail.
response {"code":400,"details":"Request problems detected","description":"There is a problem with your request. Refer to the documentation for further information.","information":"There was a problem with the database: Parse error on line 1 at character 0 when parsing '{\"data\":\"SELECT * FROM person WHERE age > 18\"}'"}
Steps to reproduce
perl useragent post request:
Expected behaviour
please guide what's problem.
curl -X POST \ -u "root:root" \ -H "NS: myapplication" \ -H "DB: myapplication" \ -H "Accept: application/json" \ -d "SELECT * FROM person WHERE age > 18" \ http://localhost:8000/sql
curl request sucess.
SurrealDB version
surreal-v1.0.0-beta.8.windows-amd64
Contact Details
No response
Is there an existing issue for this?
Code of Conduct