服务器403(禁止访问)错误并从IDictionary编码url [英] Server 403(Forbidden) error and encode url from IDictionary
问题描述
大家好,
我在Windows Web服务上遇到问题.尽管我尚未对代码进行任何更改,但最近我一直收到此错误.我正在尝试做的是连接到Web服务并拨打电话并获得响应.因此,如果我可以得到响应,则可以将XML写入字符串.但是现在失败了,直接进入我的catch语句.
奇怪的是,当我将URL放置到浏览器中时,我可以访问XML.
在此之上;
为了拨打电话,我使用的是IDictionary.
代码像这样;
Hello all,
I am facing a problem on a windows web service. Although I havent made any changes on my code, lately I ve been receiving this error. What I am trying to do is connecting to a web service and make a call and get a responce. So if i can get a responce I have a XML written to a string. But now it fails and goes directly to my catch statement.
The weird thing is, I can access the XML when I put the URL to the browser.
In addition to that;
in order to make a call I am using a IDictionary.
the code goes like that;
IDictionary<string, string> r3 = new Dictionary<string, String>();
r3["Service"] = "ECommerceService";
r3["Operation"] = "ItemLookup";
r3["ItemId"] = asin;
r3["MerchantId"] = "Featured";
r3["ResponseGroup"] = "Medium,OfferFull,Reviews";
string urlReq = HttpUtility.UrlDecode(r3.Values.ToString());
requestUrl = helper.Sign(urlReq);
这是行不通的,因为在请求url上它的显示方式为:
-http://onca/xml?AccessKeyId = 0JB3Q7C8ZC0YD8WE7BG2& System.Collections.Generic.Dictionary`2 [System.String,System.String] =& Timestamp = 2011-02-14T19:00:13Z
在此处的链接上,"
This doesnt work because on the request url it apeears as;
- http://onca/xml?AccessKeyId=0JB3Q7C8ZC0YD8WE7BG2&System.Collections.Generic.Dictionary`2[System.String,System.String]=&Timestamp=2011-02-14T19:00:13Z
On the link here "
System.Collections.Generic.Dictionary`2[System.String,System.String]=&
应该有价值.
正确的必须是;
-http://onca/xml?AccessKeyId = 0JB3Q7C8ZC0YD8WE7BG2& ItemId = B000E2EZDM& MerchantId = Featured& Operation = ItemLookup& ResponseGroup = Medium%2COfferFull%2CReviews& amp; amp; amp; amp; amp; amp; 3; Service = AWSTCommerce = 14 br/>
因此,代替"
" there should be values.
The correct must be ;
-http://onca/xml?AccessKeyId=0JB3Q7C8ZC0YD8WE7BG2&ItemId=B000E2EZDM&MerchantId=Featured&Operation=ItemLookup&ResponseGroup=Medium%2COfferFull%2CReviews&Service=AWSECommerceService&Timestamp=2011-02-14T17%3A14%3A25Z&
So instead of "
System.Collections.Generic.Dictionary`2[System.String,System.String]=&
我需要在这里使用"
" i need this there"
&ItemId=B000E2EZDM&MerchantId=Featured&Operation=ItemLookup&ResponseGroup=Medium%2COfferFull%2CReviews&Service=AWSECommerceService&
"
为了得到那个,我怎样才能从IDictionary获得它,有人可以帮忙吗?我也愿意接受新想法吗?
我在想什么,但还没弄清楚;我试过了
"
In order to get that how can I get it from IDictionary like that can someone help? I am open to new ideas as well?
What I am thinking but cant figure out yet; I tried
string urlReq = "";
foreach (string url in r3.Values)
{
urlReq = r3[url] + "&";
}
urlReq = urlReq.Substring(0, urlReq.Length - 1);
urlReq = HttpUtility.UrlDecode(urlReq);
但是这个foreach是错误的.正确的方法是什么?希望我清楚.
谢谢.
But this foreach is faulty. what is the proper way for it? I hope I am clear.
Thanks.
推荐答案
尝试一下:
Try this:
IDictionary<string, string> r3 = new Dictionary<string, string>();
r3["Service"] = "ECommerceService";
r3["Operation"] = "ItemLookup";
r3["ItemId"] = "asin";
r3["MerchantId"] = "Featured";
r3["ResponseGroup"] = "Medium,OfferFull,Reviews";
var urlString = String.Join(string.Empty, r3.Select(it => String.Format("&{0}={1}", it.Key, it.Value)));
urlString
现在将是:& Service = ECommerceService& Operation = ItemLookup& ItemId = asin& MerchantId = Featured& ResponseGroup = Medium,OfferFull,Reviews
urlString
will now be: &Service=ECommerceService&Operation=ItemLookup&ItemId=asin&MerchantId=Featured&ResponseGroup=Medium,OfferFull,Reviews
这篇关于服务器403(禁止访问)错误并从IDictionary编码url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!