I'm using RestSharp to talk to the UPS API.
I have POSTMAN and I can talk to the API just fine however when I port it over to c# I get back an empty value for response.Content.
private void button2_Click(object sender, EventArgs e)
{
label1.Text = CustomerName;
MessageBox.Show(username);
MessageBox.Show(password);
MessageBox.Show(Lic);
try
{
var client = new RestClient("https://wwwcie.ups.com/rest/Track");
var request = new RestRequest(Method.POST);
request.AddHeader("postman-token", "73a23cf5-558a-9a83-ec80-4a224b35351a");
request.AddHeader("cache-control", "no-cache");
request.AddHeader("content-type", "application/json");
request.AddParameter("application/json", "{\r\n \"UPSSecurity\": {\r\n \"UsernameToken\": {\r\n \"Username\": " + username + ",\r\n \"Password\": " + password + "\r\n },\r\n \"ServiceAccessToken\": {\r\n \"AccessLicenseNumber\": " + Lic + "\r\n }\r\n },\r\n \"TrackRequest\": {\r\n \"Request\": {\r\n \"RequestAction\": \"Track\",\r\n \"RequestOption\": \"activity\"\r\n },\r\n \"InquiryNumber\": " + textBox1.Text.Trim() + "\r\n }\r\n}", ParameterType.RequestBody);
string result = "";
request.Timeout = 10000;
//IRestResponse response = client.Execute(request);
client.ExecuteAsync(request, (response) =>
{
result = response.Content;
MessageBox.Show(result);
}
);
}
catch (Exception err)
{
MessageBox.Show(err.ToString());
}
}
Everything looks fine to me but I'm not sure where I have the problem at, I looked through past articles and noticed the ExecuteAsync so I tried that solution however it is still empty.
Thanks for any help.