700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > [Qt] network使用post时含有中文 reply 接收报错 bad request 错误码400

[Qt] network使用post时含有中文 reply 接收报错 bad request 错误码400

时间:2023-08-24 13:32:32

相关推荐

[Qt] network使用post时含有中文 reply 接收报错 bad request 错误码400

描述:

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 "中文"

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。