sofa-pbrpc icon indicating copy to clipboard operation
sofa-pbrpc copied to clipboard

HTTP的GET消息格式修改

Open hebutliu2010 opened this issue 9 years ago • 1 comments

在使用sofa-pbrpc时,经常会遇到get消息中参数很少的情况,比如:http://XXX/ip2location.parse?request={"ip":"124.117.112.2"},但是常规来说大家倾向于使用http://XXX/ip2location.parse?ip=124.117.112.2的方式,所以需要对sofa-pbrpc源码进行修改: 修改sofa-pbrpc/src/sofa/pbrpc/http_rpc_request.cc:109文件: json_str = _query_params["request"]; 更新为: if(_query_params.find("request") != _query_params.end()) {
json_str = _query_params["request"]; }
if (json_str == "" && _query_params.size() != 0) {
bool add = false; json_str = "{"; for (std::map<std::string, std::string>::iterator it = _query_params.begin(); it != _query_params.end(); ++it) {
if(add) {
json_str += ","; }
else {
add = true; }
json_str += """; json_str += it->first; json_str += "":""; json_str += it->second; json_str += """; }
json_str += "}"; } 代码不是很规范,还请团队帮忙修改。

hebutliu2010 avatar Sep 14 '16 06:09 hebutliu2010

个人建议使用json通信的时候 还是在client组装好rpc要求的格式后传给server

HTTP GET中的参数是不能表达嵌套的 之后如果有这方面的需求的话还是要升级client

cyshi avatar Sep 20 '16 02:09 cyshi