Skip to content

Commit c40e0a7

Browse files
committed
Add a function to allow a raw post instead of a form post to allow for e.g. JSON
1 parent 1437bc3 commit c40e0a7

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/BizHawk.Client.Common/Api/HttpCommunication.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Collections.Generic;
22
using System.Diagnostics.CodeAnalysis;
33
using System.Net.Http;
4+
using System.Text;
45
using System.Threading.Tasks;
56

67
using BizHawk.Common;
@@ -64,6 +65,11 @@ public string ExecPostAsForm(string url = null, string payload = "")
6465
}
6566
#pragma warning restore DOC105
6667

68+
public string ExecPostRaw(string url = null, string payload = "", string contentType = "text/plain") => Post(
69+
url ?? PostUrl,
70+
new StringContent(payload, Encoding.UTF8, contentType)
71+
).Result;
72+
6773
public async Task<string> Get(string url)
6874
{
6975
_client.DefaultRequestHeaders.ConnectionClose = false;

src/BizHawk.Client.Common/lua/CommonLibs/CommLuaLibrary.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,13 +196,20 @@ public string HttpGet(string url)
196196
return APIs.Comm.HTTP?.ExecGet(url);
197197
}
198198

199-
[LuaMethod("httpPost", "makes a HTTP POST request")]
199+
[LuaMethod("httpPost", "makes a HTTP POST request with the payload form encoded as the 'payload' field")]
200200
public string HttpPost(string url, string payload)
201201
{
202202
CheckHttp();
203203
return APIs.Comm.HTTP?.ExecPostAsForm(url: url, payload: payload);
204204
}
205205

206+
[LuaMethod("httpPostRaw", "makes a HTTP POST request with the supplied payload sent directly as the body")]
207+
public string HttpPostRaw(string url, string payload, string contentType)
208+
{
209+
CheckHttp();
210+
return APIs.Comm.HTTP?.ExecPostRaw(url, payload, contentType);
211+
}
212+
206213
[LuaMethod("httpPostScreenshot", "HTTP POST screenshot")]
207214
public string HttpPostScreenshot()
208215
{

0 commit comments

Comments
 (0)