描述:
httpCode 400errorMessage: "Error transferring https://localhost:44356/api/SQLite/POST_Test - server replied: Bad Request"strReply "{\"type\":\"/html/rfc7231#section-6.5.1\",\"title\":\"One or more validation errors occurred.\",\"status\":400,\"traceId\":\"00-2910bdf598e4fd458bcbb9470c1d88b3-67fd86b70223224f-00\",\"errors\":{\"$\":[\"The JSON value could not be converted to System.String. Path: $ | LineNumber: 0 | BytePositionInLine: 6.\"]}}"```QString strUrl;QString strerrorMessage;QString strReply;QString strRequest = "\"中文\""; //"\"123\"" 要加转义符qDebug()<<"strRequest"<<strRequest;strUrl = "https://localhost:44356/api/SQLite/POST_Test";NetWorkHelper netHelper;netHelper.POSTToApi(strUrl, strRequest,strerrorMessage,strReply);qDebug()<<"strReply"<<strReply;
解决方法:
NetReply = NetAccessManager.post(NetRequest, requestStr.toUtf8());
调用toUtf8将字符串转换为UTF-8编码
成功:
strRequest "\"中文\""httpCode 200strReply "中文"