Quantcast
Channel: Photon Server — Photon Engine
Viewing all articles
Browse latest Browse all 1557

Async request in OnRaiseEvent

$
0
0
Hi, I'm trying to make a async web request to post json and I find the example a little bit confusing
https://doc.photonengine.com/en-us/server/current/plugins/manual#outbound_http_calls


In the following example, Async flag is set with WebFlags.ShouldSendSync(), how is it different from just async = true (for async request) and async = false (for non async request)?
public override void OnRaiseEvent(IRaiseEventCallInfo info)
{
HttpRequest request = new HttpRequest()
{
Callback = OnHttpResponse,
Url = "https://requestb.in/<token>", // change URL
Async = !WebFlags.ShouldSendSync(info.Request.WebFlags),
UserState = info
};
// here you can modify the request to suit your needs
PluginHost.HttpRequest(request);
info.Defer();
}


Next example - I'm assuming this is non async request since Async flag is not set
What happens if I pass a Async flag
Async = WebFlags.ShouldSendSync(info.Request.WebFlags) or Async = false
Will it still make non async request?

void PostJson(string url, HttpRequestCallback callback, string json)
{
var stream = new MemoryStream();
var data = Encoding.UTF8.GetBytes(json);
stream.Write(data, 0, data.Length);
HttpRequest request = new HttpRequest()
{
Callback = callback,
Url = url,
DataStream = stream,
Method = "POST",
ContentType = "application/json"
};
// here you can modify the request to suit your needs
PluginHost.HttpRequest(request);
}

Ultimately I want to have a method that PostJson and be able make either async or non async by passing a parameter


Viewing all articles
Browse latest Browse all 1557