diff --git a/src/BizHawk.Client.Common/Api/HttpCommunication.cs b/src/BizHawk.Client.Common/Api/HttpCommunication.cs index be64aec4bd6..8e229fec2dc 100644 --- a/src/BizHawk.Client.Common/Api/HttpCommunication.cs +++ b/src/BizHawk.Client.Common/Api/HttpCommunication.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Net.Http; +using System.Text; using System.Threading.Tasks; using BizHawk.Common; @@ -64,6 +65,15 @@ public string ExecPostAsForm(string url = null, string payload = "") } #pragma warning restore DOC105 + public string ExecPostRaw(string url = null, string payload = "", string contentType = "text/plain") + { + return Post( + url ?? PostUrl, + new StringContent(payload, Encoding.UTF8, contentType), + payload.Length > ExpectContinueThreshold + ).Result; + } + public async Task Get(string url) { _client.DefaultRequestHeaders.ConnectionClose = false; diff --git a/src/BizHawk.Client.Common/lua/CommonLibs/CommLuaLibrary.cs b/src/BizHawk.Client.Common/lua/CommonLibs/CommLuaLibrary.cs index 5d30328994e..cb48c3732ed 100644 --- a/src/BizHawk.Client.Common/lua/CommonLibs/CommLuaLibrary.cs +++ b/src/BizHawk.Client.Common/lua/CommonLibs/CommLuaLibrary.cs @@ -196,13 +196,20 @@ public string HttpGet(string url) return APIs.Comm.HTTP?.ExecGet(url); } - [LuaMethod("httpPost", "makes a HTTP POST request")] + [LuaMethod("httpPost", "makes a HTTP POST request with the payload form encoded as the 'payload' field")] public string HttpPost(string url, string payload) { CheckHttp(); return APIs.Comm.HTTP?.ExecPostAsForm(url: url, payload: payload); } + [LuaMethod("httpPostRaw", "makes a HTTP POST request with the supplied payload sent directly as the body")] + public string HttpPostRaw(string url, string payload, string contentType) + { + CheckHttp(); + return APIs.Comm.HTTP?.ExecPostRaw(url, payload, contentType); + } + [LuaMethod("httpPostScreenshot", "HTTP POST screenshot")] public string HttpPostScreenshot() {