Question: C# - I have created a program to ask for purchase order information and stored the result in a object called generate. I now have

C# - I have created a program to ask for purchase order information and stored the result in a object called generate. I now have an API client/server project that is supposed to take the object generate and post it to the server through the client project. The instructor has indicated the post method is where I need to change the code to use object generate. Any ideas how to do this? My API client code is below. Any help is appreciated.

static void Main(string[] args) {

HttpClient client = new HttpClient(); string result = null;

// NOTE: You will need to ensure that the URL is the same on your machine!

var response = client.GetAsync("http://localhost:49536/api/EDI/").GetAwaiter().GetResult();

if( response.IsSuccessStatusCode ) { result = response.Content.ReadAsStringAsync().GetAwaiter().GetResult(); Console.WriteLine($"Result: {result}"); } else { Console.WriteLine("Error"); }

// NOTE: You will need to ensure that the URL is the same on your machine!

// IMPORTANT: The = sign at the beginning of the string is required since we are passing the data as application/x-www-form-urlencoded // if it is omitted, the string will not be passed. response = client.PostAsync("http://localhost:49536/api/EDI/", new StringContent("=BEG*00*SA*548177**20030627~REF*AN*547794~PER*BD*JOHN JONES*TE*5552225555~FOB*PB~DTM*002*20030705~DTM*118*20030704~PKG******01~TD5****H*OUR CR/T~N9*AH*548177~MSG*THIS PURCHASE ORDER IS SUBJECT TO THE SAME TERMS AND~MSG*CONDITIONS AS SAFEWAY PURCHASE ORDER FORM 1030~MSG*PICKUP NO. E450562~N1*ST*SAFEWAY INC*9*009137209252", Encoding.UTF8, "application/x-www-form-urlencoded")).GetAwaiter().GetResult(); if (response.IsSuccessStatusCode) { result = response.Content.ReadAsStringAsync().GetAwaiter().GetResult(); Console.WriteLine($"Result: {result}"); } else { Console.WriteLine("Error"); } Console.ReadKey();

} } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!