Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Big Data, Mining, And Analytics Components Of Strategic Decision Making

Authors: Stephan Kudyba

1st Edition

1466568704, 9781466568709

Students also viewed these Databases questions