birmarco
11-01-2014, 14:06
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:
"Couldn\u0027t create SOAP message due to exception: com.jaxws.json.codec.JSONFault: Input string is not well formed JSON (invalid char \uffff)"
In sostanza non gli piace il JSON che gli mando e dà errore nel parsing. Non so esattamente che JSON abbia bisogno del server in questione (non è mio...), so solo che il sito web che gira su questo server, questa richiesta, la effettua con questo codice AJAX:
.......
url : URLp,
dataType : 'json',
type : 'POST',
data: {
A: $a,
B: $b,
C: $c,
D: $d
},
success : function(data) ......
Il codice C# che uso io per la richiesta è questo:
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"));
Mi piacerebbe capire quale sia l'esatto output di quel codice Ajax sia del mio C#, ma non so come fare a guardarlo.
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 :)
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:
"Couldn\u0027t create SOAP message due to exception: com.jaxws.json.codec.JSONFault: Input string is not well formed JSON (invalid char \uffff)"
In sostanza non gli piace il JSON che gli mando e dà errore nel parsing. Non so esattamente che JSON abbia bisogno del server in questione (non è mio...), so solo che il sito web che gira su questo server, questa richiesta, la effettua con questo codice AJAX:
.......
url : URLp,
dataType : 'json',
type : 'POST',
data: {
A: $a,
B: $b,
C: $c,
D: $d
},
success : function(data) ......
Il codice C# che uso io per la richiesta è questo:
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"));
Mi piacerebbe capire quale sia l'esatto output di quel codice Ajax sia del mio C#, ma non so come fare a guardarlo.
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 :)