简体   繁体   English

通过C ++桌面应用程序发送发布请求

[英]Sending a post request via C++ desktop application

I'm using SFML::Network to access my web server and send it high scores. 我正在使用SFML :: Network来访问我的Web服务器并向其发送高分。 The high scores are recieved by a PHP script that stores them on a JSON file: 将脚本存储在JSON文件中的PHP脚本会收到较高的分数:

...
$name = $_POST["n"];
$validator = $_POST["v"];
$score = $_POST["s"];
...

I'm currently sending a POST request from C++ like this: 我目前正在从C ++发送这样的POST请求:

...
Http http; http.setHost("http://mywebsite.com");
Request request("script.php", Http::Request::Post);
request.setBody("n=" + mName + "&v=" + mValidator + "&s=" + toStr(mScore));
http.sendRequest(request);
...

This works, but has the same limitations as a GET request - especially character limit. 此方法有效,但与GET请求具有相同的限制-尤其是字符数限制。 Since I need to validate the high scores for custom levels made in LUA, I wanted to pass the whole LUA file (stripped of symbols and whitespace) as mValidator. 由于我需要验证LUA中自定义级别的高分,因此我希望将整个LUA文件(带符号和空格的部分)作为mValidator传递。 But it doesn't work with 1000 characters. 但是它不能用于1000个字符。 Small strings work properly. 小字符串正常工作。

I've been told that character limit is only present in GET requests, and that I'm calling the POST request in the wrong way. 有人告诉我,字符限制仅出现在GET请求中,而我以错误的方式调用POST请求。

How can I call the POST request correctly and avoid the character limit without compressing my parameters? 如何在不压缩参数的情况下正确调用POST请求并避免字符限制?

1000 characters should work fine. 1000个字符应该可以正常工作。 Check to make sure your string is properly encoded. 检查以确保您的字符串正确编码。 A content-type of x-www-form-urlencoded should be URL encoded. x-www-form-urlencoded的内容类型应进行URL编码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM