Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Getting result of a task
Message
De
21/11/2016 06:20:14
 
 
Information générale
Forum:
ASP.NET
Catégorie:
Common Language Runtime
Versions des environnements
Environment:
C# 5.0
OS:
Windows 10
Database:
MS SQL Server
Divers
Thread ID:
01643645
Message ID:
01643743
Vues:
34
>>>Hi everybody,
>>>
>>>I've defined the following method:
>>>
>>>
>>>static async Task<HttpResponseMessage> GetResponse(TicketUsageRequests ticket, string apiUrl)
>>>        {
>>>            HttpResponseMessage response = await client.PostAsJsonAsync(apiUrl, ticket);
>>>            //response.EnsureSuccessStatusCode();
>>>            
>>>            return response;
>>>        }
>>>
>>>My question is - how can I get its result in the main method code and synchronously?
>>>
>>>My current method is:
>>>
>>>
>>>try
>>>            {               
>>>                SetRequestHeaders(tcHost, tcUserName, tcPassword, tnTimeout, tnRetries);
>>>
>>>                TicketUsageRequests ticket = new TicketUsageRequests();
>>>                ticket.TicketBarcode = tcBarcode;
>>>                ticket.TicketUsageDate = tcUsageDate;
>>>                ticket.UserID = tcUserName;
>>>
>>>               ... here I want to get the result of the response and parse it
>>>
>>>   ...
>>>
>>>
>>>I found this
>>>
>>>http://stackoverflow.com/questions/5095183/how-would-i-run-an-async-taskt-method-synchronously
>>>
>>>and trying to figure out how to apply pixel's solution.
>>>
>>>Thanks in advance.
>>
>>Not 100% sure but just try:
HttpResponseMessage response = client.PostAsJsonAsync(apiUrl, ticket).Result;
>
>Do you know how can I debug that? I'm getting back 'Bad Request' - how can I see what exactly I am sending?

Network tab on the browser debugger should show you the request ?

Update: just realised that this must be on the server - in which case Fiddler should let you see the request that went over the wire
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform