-1

I want use mIRC to create a folder on Dropbot

But the echo always get this message:

400 Bad Request
The plain HTTP request was sent to HTTPS port

I have no idea why it happens. This is my code:

alias dropboxCreateFolder {
  sockclose dropboxCreateFolder
  sockopen dropboxCreateFolder api.dropboxapi.com 443
}

ON *:SOCKOPEN:dropboxCreateFolder: {
  if ($sockerr) { sockclose $sockname | halt }
  var %data = {"path":"/myfile/songs"}
  sockwrite -nt $sockname POST /2/files/create_folder HTTP/1.1
  sockwrite -nt $sockname Host: api.dropboxapi.com
  sockwrite -nt $sockname User-Agent: api-explorer-client
  sockwrite -nt $sockname Authorization: Bearer Access_Token
  sockwrite -nt $sockname Content-Type: application/json
  sockwrite -nt $sockname $crlf $+ %data
}

ON *:SOCKREAD:dropboxCreateFolder: {
  if ($sockerr) { sockclose $sockname | halt }
  else {
    var %sockreader | sockread %sockreader 
    echo -s %sockreader
  }
}
Pang
  • 9,564
  • 146
  • 81
  • 122
JerryYou
  • 1
  • 1

2 Answers2

1

1- You're not using SSL. This is a dropbox API requirement.

2- You're not setting a Content-Length header, you should really do this when POSTing.

alias dropboxCreateFolder {
  sockclose dropboxCreateFolder
  sockopen -e dropboxCreateFolder api.dropboxapi.com 443
}

ON *:SOCKOPEN:dropboxCreateFolder: {
  if ($sockerr) { sockclose $sockname | halt }
  var %data = {"path":"/myfile/songs"}
  sockwrite -nt $sockname POST /2/files/create_folder HTTP/1.1
  sockwrite -nt $sockname Host: api.dropboxapi.com
  sockwrite -nt $sockname User-Agent: api-explorer-client
  sockwrite -nt $sockname Authorization: Bearer Access_Token
  sockwrite -nt $sockname Content-Type: application/json
  sockwrite -nt $sockname Content-Length: $len(%data)
  sockwrite -nt $sockname $crlf $+ %data
}

ON *:SOCKREAD:dropboxCreateFolder: {
  if ($sockerr) { sockclose $sockname | halt }
  else {
    var %sockreader | sockread %sockreader 
    echo -s %sockreader
  }
}
JD Byrnes
  • 783
  • 6
  • 17
0

The error you showed tells you that you send a plain HTTP request to a HTTPS port. This means that api.dropboxapi.com expects SSL connections to be made on port 443, but you're attempting to create a non-SSL connection.

You need to specify the -e switch in your sockopen command to create an SSL connection instead.

Patrickdev
  • 2,341
  • 1
  • 21
  • 29
  • Now I add -e after sockopen, But it show this "Error in call to API function "files/create_folder": request body: could not decode input as JSONHTTP/1.1 400 Bad Request" Is my %data wrong? – JerryYou May 09 '16 at 06:26