语法错误或访问冲突尝试将JSON数据发送到服务器时发生异常
我尝试使用c#将JSON数据发送到服务器。 这是我发布的数据代码:语法错误或访问冲突尝试将JSON数据发送到服务器时发生异常
private static string PostJSONData(string JSONdata, Uri url)
{
try
{
var httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
httpWebRequest.ContentType = "text/json";
httpWebRequest.Method = "POST";
using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
{
streamWriter.Write(JSONdata);
streamWriter.Flush();
streamWriter.Close();
}
var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
var result = streamReader.ReadToEnd();
return result;
}
}
catch (Exception ex)
{
throw ex;
}
}
我的JSON数据是这样的:
{"Key":"auth_token","Value":""},
{"Key":"request_id","Value":"14104"},
{"Key":"_number","Value":"TAQ422924"},
{"Key":"Customer","Value":"Some Customer"},
{"Key":"first_date","Value":"2014-10-24T15:52:21"}]
当我尝试发送数据,在线
var result = streamReader.ReadToEnd();
有错误用此描述
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ',,,,,,,,,,,,,,,,,)) LIMIT 1' at line 1' in /var/www/clients/client0/web16/web/library/Zend/Db/Statement/Pdo.php:228 Stack trace: /var/www/clients/client0/web16/web/library/Zend/Db/Statement/Pdo.php(228): PDOStatement-execute(Array /var/www/clients/client0/web16/web/library/Zend/Db/Statement.php(320): Zend_Db_Statement_Pdo-_execute(Array) . . .
这是什么错误?它来自一个PHP页面,我不使用任何PHP页面。
json的ContentType是“application/json”而不是“text/json”。服务器可能会将您的数据视为文本而不是json。 你json的数据也是缺少方括号'['
这是一个服务器端的错误。你的JSON数据被传送到服务器,但服务器无法将其保存在MySQL – opewix 2014-12-19 05:50:04
@JesseJames:哦,很好。那就对了。谢谢Jesse。 – 2014-12-21 22:36:33