0

I'm trying to pass the following restart command that will run in a container, into a C# command, but I'm not sure how to do it, help please:

curl --header "Content-Type:application/json" "$BALENA_SUPERVISOR_ADDRESS/v2/applications/$BALENA_APP_ID/restart-service?apikey=$BALENA_SUPERVISOR_API_KEY" -d '{"serviceName": "venue"}'
Yuki1112
  • 365
  • 2
  • 12
  • Have you taken a look at HttpClient? – phuzi Aug 30 '22 at 10:59
  • yes but I'm not sure how to implement it with the balena and json, I understand the -d '{"serviceName": "venue"}' is the task but not how to implement the rest – Yuki1112 Aug 30 '22 at 11:01
  • Take a look at the curl docs and `-d` specifies the content of a POST request which matches the `Content-Type` header which is also specified. – phuzi Aug 30 '22 at 11:04
  • Would this be enought? `using (var httpClient = new HttpClient()) { using (var request = new HttpRequestMessage(new HttpMethod("POST"), "http://$BALENA_SUPERVISOR_ADDRESS/v2/applications/$BALENA_APP_ID/restart-service?apikey=$BALENA_SUPERVISOR_API_KEY/")) { request.Content = new StringContent("{\"serviceName\": \"venue\"}"); request.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json"); var response = await httpClient.SendAsync(request); } } ` – Yuki1112 Aug 30 '22 at 11:09
  • I'm just not sure if `"$BALENA_SUPERVISOR_ADDRESS/v2/applications/$BALENA_APP_ID/restart-service?apikey=$BALENA_SUPERVISOR_API_KEY"` should go into http – Yuki1112 Aug 30 '22 at 11:19
  • Yeah, you're going to need to do some extra work to get these values replaced. – phuzi Aug 30 '22 at 11:31
  • Also consider using `HttpClient.PostAsync` and `JsonContent.Create(new {ServiceName = "venue")` instead of hand-crafting JSON. – phuzi Aug 30 '22 at 11:34

0 Answers0