语法错误或访问冲突 尝试将 JSON 数据发送到服务器时出现异常
本文关键字:服务器 异常 数据 访问冲突 错误 JSON 语法 | 更新日期: 2023-09-27 18:34:38
我尝试使用 c# 将 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();
此描述有误
致命错误:未捕获的异常"PDOException",并显示消息 'SQLSTATE[42000]:语法错误或访问冲突:1064 您有一个 您的 SQL 语法错误;检查与您的手册相对应的手册 MySQL 服务器版本,用于在附近使用的正确语法 ',,,,,,,,,,,,,,,,,( ( 限制 1' 在第 1 行 /var/www/clients/client0/web16/web/library/Zend/Db/Statement/Pdo.php:228 堆栈跟踪: /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(阵列( . . .
此错误是干什么用的???它来自一个php页面,我不使用任何php页面。
json 的 ContentType 是 "application/json" 而不是 "text/json"。服务器可能会将您的数据视为文本而不是 json。您的 json 数据也缺少前导方括号"[">