【问题标题】:Angular: why $http GET params encrypted?Angular:为什么要加密 $http GET 参数?
【发布时间】:2015-07-22 13:38:41
【问题描述】:

我有一个GET 方法,但由于某种原因它发送加密的params

var request = function (apiMethod, apiResponse) {

            var deferred = $q.defer();

            var apiPath = getApiPath();

            apiPath = $rootScope.ROOT_URL + apiPath;

            var config = {
                method: 'GET',
                url: apiPath + apiMethod,
                params: 'email=myemail@gmail.com, timestamp_start=1432801800, timestamp_end=1432803600, organizer_email= myemail@gmail.com, cloudinary_rules=scale, meeting_name=123',
                //data: apiResponse,
                //headers: {'Content-Type': 'application/x-www-form-urlencoded'},
                //withCredentials: true,
                timeout: canceler.promise
            };
            $http.get(config).success(function (data) {

                $rootScope.showLoader = false;

                if (data.message === undefined) {
                    deferred.resolve(data);
                } else {
                    deferred.reject(data);
                }

            }).error(function (data, status, headers, config) {
                $rootScope.showLoader = false;
                deferred.reject(data);
            });
            return deferred.promise;
        };

但是我收到的请求是:

https://myapp.me/api.php/get_gadget_notes?0=e&1=m&10=a&100=d&101=a&102=c&103=o&104=r&105=p&106=@&107=g&108=m&109=a&11=c&110=i&111=l&112=.&113=c&114=o&115=m&116=,&117=+&118=c&119=l&12=o&120=o&121=u&122=d&123=i&124=n&125=a&126=r&127=y&128=&129=r&13=r&130=u&131=l&132=e&133=s&134=%3D&135=s&136=c&137=a&138=l&139=e&14=p&140=,&141=+&142=m&143=e&144=e&145=t&146=i&147=n&148=g&149=&15=@&150=n&151=a&152=m&153=e&154=%3D&155=1&156=2&157=3&16=g&17=m&18=a&19=i&2=a&20=l&21=.&22=c&23=o&24=m&25=,&26=+&27=t&28=i&29=m&3=i&30=e&31=s&32=t&33=a&34=m&35=p&36=&37=s&38=t&39=a&4=l&40=r&41=t&42=%3D&43=1&44=4&45=3&46=2&47=8&48=0&49=1&5=%3D&50=8&51=0&52=0&53=,&54=+&55=t&56=i&57=m&58=e&59=s&6=l&60=t&61=a&62=m&63=p&64=&65=e&66=n&67=d&68=%3D&69=1&7=a&70=4&71=3&72=2&73=8&74=0&75=3&76=6&77=0&78=0&79=,&8=n&80=+&81=o&82=r&83=g&84=a&85=n&86=i&87=z&88=e&89=r&9=d&90=_&91=e&92=m&93=a&94=i&95=l&96=%3D&97=l&98=a&99=n

如何发送正确的 GET 请求?

【问题讨论】:

    标签: angularjs http http-get


    【解决方案1】:

    你应该尝试给他一个对象而不是一个字符串:

     var config = {
                method: 'GET',
                url: apiPath + apiMethod,
                params: {
                   email:"myemail@gmail.com",
                   timestamp_start:1432801800,
                   timestamp_end:1432803600,
                   [etc...]
                }
                //data: apiResponse,
                //headers: {'Content-Type': 'application/x-www-form-urlencoded'},
                //withCredentials: true,
                timeout: canceler.promise
            };
    

    它可能试图将整个字符串作为一个参数进行 URL 编码,但不确定。

    希望对您有所帮助。

    编辑:哈哈,重新阅读获取请求。

    它实际上将字符串作为参数数组。所以它将每个字母作为一个参数发送(查看参数顺序:0:e - 1:m - 2:a(ema...)[etc...]。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-08-18
      • 2014-06-26
      • 1970-01-01
      • 1970-01-01
      • 2019-06-09
      • 1970-01-01
      • 2010-12-03
      相关资源
      最近更新 更多