Lua -上传到Pastebin

注意这是 Roblox 版本的 lua。 我想上传一个表格到 Pastebin。这里是我为 Pastebin 准备的代码。

h = game:GetService'HttpService'
JSON = h:JSONEncode(ImgScript) --ImgScript 是一个格式为 {{x,y,z}, {x,y,z}, {x,y,z}, 等等的表格。}
h:PostAsync('http://pastebin.com/api/api_post.php','&api_dev_key=CensoredDevKey&api_option=paste&api_paste_code=' .. JSON)

这并不起作用,我似乎弄不清为什么。

编辑: 我也尝试过这个,但它也没有起作用。

h = game:GetService'HttpService'
api_params = {
    ["api_dev_key"] = "CensoredDevKey",
    ["api_option"] = "paste",
    ["api_paste_code"] = ImgScript
}
api_params = h:JSONEncode(api_params)
h:PostAsync('http://www.pastebin.com/api/api_post.php', api_params)

编辑: 我也尝试过这个,但它也没有起作用。

h = game:GetService'HttpService'
JSON = h:JSONEncode(ImgScript) --ImgScript 是一个格式为 {{x,y,z}, {x,y,z}, {x,y,z}, 等等的表格。}
data = h:UrlEncode('&api_dev_key=CensoredDevKey&api_option=paste&api_paste_code=' .. JSON)
h:PostAsync('http://pastebin.com/api/api_post.php', data)
点赞
用户1190388
用户1190388

试试以下代码:

h = game:GetService'HttpService'
pasteData = h:UrlEncode( h:JSONEncode(ImgScript) )
h:PostAsync(
    'http://pastebin.com/api/api_post.php',
    'api_dev_key=CensoredDevKey&api_option=paste&api_paste_code=' .. pasteData,
    2
)

最后一个参数 2 指定 发送的数据为 Application/Url-Encoded

我觉得应该可以用。如果不行,请在这里告诉我。

附注:你从这个POST请求中收到的结果在哪里?

2015-09-24 06:26:08
用户3600300
用户3600300

所以我完成了代码,但是不幸的是,Roblox将 PostAsync大小限制为256字节,因此任何大于该大小的上传将被GZIPed(最多为1024kb),而Pastebin不知道该如何处理。

无论如何,我在这里发布了代码: http://www.roblox.com/Pastebin-Upload-item?id=302297532

它是:

--由GShocked创建。如果您有问题,请私信我!

h = game:GetService'HttpService'
api_dev_key = '' -- 您的Pastebin开发人员密钥在此处。首先登录,然后您可以在pastebin.com/api上找到它
api_paste_code = '' -- 您的新粘贴内容
api_paste_private = '1' --0公开; 1未列出; 2私人
api_paste_name = '' --为您的新粘贴命名
api_paste_expire_date = 'N' --N表示永不过期,10M表示10分钟等
api_paste_format = 'lua' --语法突出显示
api_user_key = '' --这是使用登录信息生成的
api_paste_name = h:UrlEncode(api_paste_name)
api_paste_code = h:UrlEncode(api_paste_code)
username = '' --您的Pastebin用户名在此处
password = '' --您的Pastebin密码在此处

api_user_key = h:PostAsync(
    'http://pastebin.com/api/api_login.php',
    'api_dev_key=' .. api_dev_key .. '&api_user_name=' .. username .. '&api_user_password=' .. password,
    2
)
print(api_user_key) --不要删除这个! 它对于生成用户密钥至关重要!
h:PostAsync(
    'http://pastebin.com/api/api_post.php',
    'api_option=paste&api_user_key=' .. api_user_key .. '&api_paste_private=' .. api_paste_private .. '&api_paste_name=' .. api_paste_name .. '&api_paste_expire_date=' .. api_paste_expire_date .. '&api_paste_format=' .. api_paste_format .. '&api_dev_key=' .. api_dev_key .. '&api_paste_code=' .. api_paste_code,
    2
)
2015-10-25 18:37:52