通过htaccess进行GET和POST重定向/代理

编程入门 行业动态 更新时间:2024-10-15 18:24:26
本文介绍了通过htaccess进行GET和POST重定向/代理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

有一个网站要求ajax提供一些Web服务Web方法.我没有它的代码. 它发送POST请求,并期望得到JSON作为答案. 我写了这个网络服务.我使用具有许多重写规则的hataccess文件. 一些规则直接或通过代理重定向客户端请求. 因此,有些保留POST请求,例如通过的请求 RewriteCond%{HTTP_REFERER} ^ (.*)/Bing $ [NC] RewriteRule/ActivitiesService.asmx/GetLatest$ %1/ActivitiesService.asmx/GetLatestSearchActivities [NC,L,P] 还有一些我重写了queryString形式: RewriteCond%{HTTP_REFERER} ^ (.*)/([0-9] +)[NC] RewriteRule/ActivitiesService.asmx/GetLatest$ %1/ActivitiesService.asmx/GetLatestByActivityType?activityType =%2& type = 1& timestamp = 10000 [NC,L,R = 301] 我这样做是因为我没有找到一种向该方法动态添加附加参数的方法. 我无法将其留在POST方法中. 添加了用querySring调用的方法 [ScriptMethod(UseHttpGet = true)] 问题是当我[R]重定向而不是 代理丢失一些数据: 内容类型:application/json; charset = UTF-8变成带有``xml''的东西). 即使当我将Fiddler requestBuilder与该数据一起使用时,也是如此 我得到JSON作为响应,但其中包含错误. 我试图从另一个没有的方法中调用一个方法 ScriptMethod(UseHttpGet = true)]并由重定向 -一切都很好.如预期的那样获得了良好的JSON对象. 有人知道如何修改htaccess文件或Web服务API属性? <code> [CODE] RewriteRule ^/Bing $ %{HTTP:Host} [NC,L,P] RewriteRule ^/Zynga $ %{HTTP:Host} [NC,L,P] RewriteRule ^/([[0-9] +)$ %{HTTP:Host} [NC,L,P] RewriteRule ^/CT([0-9] +)$ %{HTTP:Host} [NC,L,P] RewriteCond%{HTTP_REFERER} ^ (.*)/Bing $ [NC] RewriteRule/ActivitiesService.asmx/GetLatest$ %1/ActivitiesService.asmx/GetLatestSearchActivities [NC,L,P] RewriteCond%{HTTP_REFERER} ^ (.*)/Bing $ [NC] RewriteRule/images/ConduitLive_header.png$ %1/images/Header_WatchItBing.png [NC,L,R = 301] RewriteCond%{HTTP_REFERER} ^ (.*)/Zynga $ [NC] RewriteRule/ActivitiesService.asmx/GetLatest$ %1/ActivitiesService.asmx/GetLatestZyngaActivities [NC,L,P] RewriteCond%{HTTP_REFERER} ^ (.*)/([0-9] +)[NC] RewriteRule/ActivitiesService.asmx/GetLatest$ %1/ActivitiesService.asmx/GetLatestByActivityType?activityType =%2& type = 1& timestamp = 10000 [NC,L,R = 301] RewriteCond%{HTTP_REFERER} ^ (.*)/CT([0-9] +)[NC] RewriteRule/ActivitiesService.asmx/GetLatest$ %1/ActivitiesService.asmx/GetLatestByCtid?ctid = CT%2& type = 1& timestamp = 10000 [NC,L,R = 301] [/CODE] 感谢您的帮助! 周末愉快!

Hi, there is a website that asks with ajax for some web-service web-methods. I don''t have its code. It sends POST requests and expect to get JSON as an answer. I write this web-service. I use hataccess file with many rewrite rules. Some rules redirect client request directly or through proxy. Thus some stays POST requests, like the ones that pass through RewriteCond %{HTTP_REFERER} ^(.*)/Bing$ [NC] RewriteRule /ActivitiesService.asmx/GetLatest$ %1/ActivitiesService.asmx/GetLatestSearchActivities [NC,L,P] And some I rewrite t a queryString form: RewriteCond %{HTTP_REFERER} ^(.*)/([0-9]+) [NC] RewriteRule /ActivitiesService.asmx/GetLatest$ %1/ActivitiesService.asmx/GetLatestByActivityType?activityType=%2&type=1&timestamp=10000 [NC,L,R=301] I did so because I didn''t find a way to dynamically add an additional parameter to the method. I couldn''t leave it in POST method. The methods that are called with querySring were added [ScriptMethod(UseHttpGet = true)] the thing is that when I [R] redirect instead of proxy some data is lost: Content-Type: application/json; charset=UTF-8 turns to something with ''xml''). Even when I use Fiddler requestBuilder with this data i get JSON as a response but with an error inside it. I tried to call one method from another which doesn''t have ScriptMethod(UseHttpGet = true)] and is redirected by - and everthing worked fine. Got good JSON object as expected. Someone has an idea how can I modify my htaccess file or web-service API attributes? <code> [CODE] RewriteRule ^/Bing$ %{HTTP:Host} [NC,L,P] RewriteRule ^/Zynga$ %{HTTP:Host} [NC,L,P] RewriteRule ^/([0-9]+)$ %{HTTP:Host} [NC,L,P] RewriteRule ^/CT([0-9]+)$ %{HTTP:Host} [NC,L,P] RewriteCond %{HTTP_REFERER} ^(.*)/Bing$ [NC] RewriteRule /ActivitiesService.asmx/GetLatest$ %1/ActivitiesService.asmx/GetLatestSearchActivities [NC,L,P] RewriteCond %{HTTP_REFERER} ^(.*)/Bing$ [NC] RewriteRule /images/ConduitLive_header.png$ %1/images/Header_WatchItBing.png [NC,L,R=301] RewriteCond %{HTTP_REFERER} ^(.*)/Zynga$ [NC] RewriteRule /ActivitiesService.asmx/GetLatest$ %1/ActivitiesService.asmx/GetLatestZyngaActivities [NC,L,P] RewriteCond %{HTTP_REFERER} ^(.*)/([0-9]+) [NC] RewriteRule /ActivitiesService.asmx/GetLatest$ %1/ActivitiesService.asmx/GetLatestByActivityType?activityType=%2&type=1&timestamp=10000 [NC,L,R=301] RewriteCond %{HTTP_REFERER} ^(.*)/CT([0-9]+) [NC] RewriteRule /ActivitiesService.asmx/GetLatest$ %1/ActivitiesService.asmx/GetLatestByCtid?ctid=CT%2&type=1&timestamp=10000 [NC,L,R=301] [/CODE] Thanks for any help ! Have a great weekend

推荐答案

[NC] RewriteRule/ActivitiesService.asmx/GetLatest [NC] RewriteRule /ActivitiesService.asmx/GetLatest

%1/ActivitiesService.asmx/GetLatestSearchActivities [NC,L,P] 还有一些我重写了queryString形式: RewriteCond%{HTTP_REFERER} ^ (.*)/([0-9] +)[NC] RewriteRule/ActivitiesService.asmx/GetLatest %1/ActivitiesService.asmx/GetLatestSearchActivities [NC,L,P] And some I rewrite t a queryString form: RewriteCond %{HTTP_REFERER} ^(.*)/([0-9]+) [NC] RewriteRule /ActivitiesService.asmx/GetLatest

%1/ActivitiesService.asmx/GetLatestByActivityType?activityType =%2& type = 1& timestamp = 10000 [NC,L,R = 301] 我这样做是因为我没有找到一种向该方法动态添加附加参数的方法. 我无法将其留在POST方法中. 添加了用querySring调用的方法 [ScriptMethod(UseHttpGet = true)] 问题是当我[R]重定向而不是 代理丢失一些数据: 内容类型:application/json; charset = UTF-8变成带有``xml''的东西). 即使当我将Fiddler requestBuilder与该数据一起使用时,也是如此 我得到JSON作为响应,但其中包含错误. 我试图从另一个没有的方法中调用一个方法 ScriptMethod(UseHttpGet = true)]并由重定向 -一切都很好.如预期的那样获得了良好的JSON对象. 有人知道如何修改htaccess文件或Web服务API属性? <code> [CODE] RewriteRule ^/Bing %1/ActivitiesService.asmx/GetLatestByActivityType?activityType=%2&type=1&timestamp=10000 [NC,L,R=301] I did so because I didn''t find a way to dynamically add an additional parameter to the method. I couldn''t leave it in POST method. The methods that are called with querySring were added [ScriptMethod(UseHttpGet = true)] the thing is that when I [R] redirect instead of proxy some data is lost: Content-Type: application/json; charset=UTF-8 turns to something with ''xml''). Even when I use Fiddler requestBuilder with this data i get JSON as a response but with an error inside it. I tried to call one method from another which doesn''t have ScriptMethod(UseHttpGet = true)] and is redirected by - and everthing worked fine. Got good JSON object as expected. Someone has an idea how can I modify my htaccess file or web-service API attributes? <code> [CODE] RewriteRule ^/Bing

更多推荐

通过htaccess进行GET和POST重定向/代理

本文发布于:2023-10-11 14:11:39,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1481932.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重定向   htaccess   POST

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!