Skip to content

Commit

Permalink
chore: Tweaks to the sample HttpSend code
Browse files Browse the repository at this point in the history
In particular, this now generates a random event ID - v1.x used to
do this automatically, but in 2.x it needs to be explicit.

Signed-off-by: Jon Skeet <jonskeet@google.com>
  • Loading branch information
jskeet committed Jun 27, 2022
1 parent e517ee4 commit ee9d91a
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions samples/HttpSend/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ namespace HttpSend
// line and calling the application code. The [Option] attributes designate the parameters.
class Program
{
[Option(Description = "CloudEvents 'source' (default: urn:example-com:mysource:abc)", LongName = "source",
ShortName = "s")]
[Option(Description = "CloudEvents 'source' (default: urn:example-com:mysource:abc)", LongName = "source", ShortName = "s")]
private string Source { get; } = "urn:example-com:mysource:abc";

[Option(Description = "CloudEvents 'type' (default: com.example.myevent)", LongName = "type", ShortName = "t")]
Expand All @@ -35,6 +34,7 @@ private async Task OnExecuteAsync()
{
var cloudEvent = new CloudEvent
{
Id = Guid.NewGuid().ToString(),
Type = Type,
Source = new Uri(Source),
DataContentType = MediaTypeNames.Application.Json,
Expand All @@ -44,10 +44,10 @@ private async Task OnExecuteAsync()
var content = cloudEvent.ToHttpContent(ContentMode.Structured, new JsonEventFormatter());

var httpClient = new HttpClient();
// your application remains in charge of adding any further headers or
// Your application remains in charge of adding any further headers or
// other information required to authenticate/authorize or otherwise
// dispatch the call at the server.
var result = (await httpClient.PostAsync(this.Url, content));
var result = await httpClient.PostAsync(Url, content);

Console.WriteLine(result.StatusCode);
}
Expand Down

0 comments on commit ee9d91a

Please sign in to comment.