|
|||||||
|
|
|
![]() |
|
|
Strumenti |
|
|
#1 | |
|
Senior Member
Iscritto dal: Mar 2008
Città: Milano; 9 Vendite concluse -> Wilde; emmepi; Homerj81; cos1950; mariotanza; Benia; grigor; alekia; ARG0
Messaggi: 11160
|
[C# e AJAX] Problema invio richiesta JSON al server
Ciao a tutti!
Son tre giorni che sbatto la testa su questo problema ma non riesco a venirne a capo Sto sviluppando una PCL C# con .Net 4.5 e devo fare un POST ad un server inviandogli un JSON specifico. La richiesta la riesco ad inviare correttamente (?), ma il server mi restituisce un messaggio di errore, nello specifico: Quote:
Codice:
.......
url : URLp,
dataType : 'json',
type : 'POST',
data: {
A: $a,
B: $b,
C: $c,
D: $d
},
success : function(data) ......
Codice:
HttpClient httpClient = new HttpClient(handler);
string resourceAddress = "http://*******";
string postBody = "[{ 'A' : " + a +
", 'B' : " + b +
", 'C' : " + c +
", 'D' : " + d + " }]";
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
HttpResponseMessage requestResponse = await httpClient.PostAsync(resourceAddress, new StringContent(postBody, Encoding.UTF8, "application/json"));
PS. Per il JSON che mando io ho provato sia usando gli apici singoli, che doppi, sia mettendo che togliendo quelle quadre. Le variabili a, b, c, d sono numeri Grazie a tutti |
|
|
|
|
|
|
#2 |
|
Senior Member
Iscritto dal: Feb 2003
Città: Stockholm (SE)
Messaggi: 1343
|
invece di crearti il json a mano, fatti una classe che rappresenta il tuo oggetto e serializzalo in JSON con JSON.NET
|
|
|
|
|
|
#3 |
|
Senior Member
Iscritto dal: Mar 2008
Città: Milano; 9 Vendite concluse -> Wilde; emmepi; Homerj81; cos1950; mariotanza; Benia; grigor; alekia; ARG0
Messaggi: 11160
|
|
|
|
|
|
| Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 12:06.




















