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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started