allow use of any http method
This commit is contained in:
@@ -156,13 +156,13 @@ namespace Barotrauma
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
public void HttpPost(string url, LuaCsAction callback, string data, string contentType = "application/json")
|
public void HttpRequest(string url, LuaCsAction callback, string data, string method = "POST", string contentType = "application/json")
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
|
var httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
|
||||||
httpWebRequest.ContentType = contentType;
|
httpWebRequest.ContentType = contentType;
|
||||||
httpWebRequest.Method = "POST";
|
httpWebRequest.Method = method;
|
||||||
|
|
||||||
using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
|
using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
|
||||||
streamWriter.Write(data);
|
streamWriter.Write(data);
|
||||||
@@ -191,33 +191,15 @@ namespace Barotrauma
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void HttpGet(string url, LuaCsAction callback)
|
public void HttpPost(string url, LuaCsAction callback, string data, string contentType = "application/json")
|
||||||
{
|
{
|
||||||
try
|
HttpRequest(url, callback, data, "POST", contentType);
|
||||||
{
|
}
|
||||||
var httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
|
|
||||||
|
|
||||||
httpWebRequest.BeginGetResponse(new AsyncCallback((IAsyncResult result) =>
|
|
||||||
{
|
public void HttpGet(string url, LuaCsAction callback, string data, string contentType = "application/json")
|
||||||
try
|
{
|
||||||
{
|
HttpRequest(url, callback, data, "GET", contentType);
|
||||||
var httpResponse = httpWebRequest.EndGetResponse(result);
|
|
||||||
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
|
|
||||||
{
|
|
||||||
string responseResult = streamReader.ReadToEnd();
|
|
||||||
GameMain.LuaCs.Timer.Wait((object[] par) => { callback(responseResult); }, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
GameMain.LuaCs.Timer.Wait((object[] par) => { callback(e.Message); }, 0);
|
|
||||||
}
|
|
||||||
}), null);
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
GameMain.LuaCs.Timer.Wait((object[] par) => { callback(e.Message); }, 0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async void HandleIncomingConnections(System.Net.HttpListener listener, LuaCsAction onRequestReceived)
|
public static async void HandleIncomingConnections(System.Net.HttpListener listener, LuaCsAction onRequestReceived)
|
||||||
|
|||||||
Reference in New Issue
Block a user