Skip to content

Commit 4ac1d53

Browse files
committed
Add a function to allow a raw post instead of a form post to allow for e.g. JSON
1 parent ca0ad58 commit 4ac1d53

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Collections.Generic;
22
using System.Net.Http;
3+
using System.Text;
34
using System.Threading.Tasks;
45

56
using BizHawk.Common;
@@ -41,6 +42,11 @@ public string ExecPost(string url = null, string payload = "")
4142
).Result;
4243
}
4344

45+
public string ExecPostRaw(string url = null, string payload = "", string contentType = "text/plain") => Post(
46+
url ?? PostUrl,
47+
new StringContent(payload, Encoding.UTF8, contentType)
48+
).Result;
49+
4450
public async Task<string> Get(string url)
4551
{
4652
_client.DefaultRequestHeaders.ConnectionClose = false;
@@ -52,7 +58,7 @@ public async Task<string> Get(string url)
5258
return null;
5359
}
5460

55-
public async Task<string> Post(string url, FormUrlEncodedContent content)
61+
public async Task<string> Post(string url, HttpContent content)
5662
{
5763
_client.DefaultRequestHeaders.ConnectionClose = true;
5864
HttpResponseMessage response;

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?.ExecPost(url, 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)