WP7 and Http-Referer
I've written an app that shows comments from Disqus and when I run it as a .NET application on my desktop it works great. It sends a http requst and then deserialize the json objects. But when I move the code to my Windows Phone app I get an error from Disqus.
It appears that because Window开发者_如何学Pythons Phone decides to add a random http referer my request fails. I'm not allowed to change the referer on the windows phone I get the message "The 'Referer' header cannot be modified directly." if I try to do that.
Is there a workaround for this that doesn't require me to build a proxy that removes the referer header?
From what I can gather from this post, there's no way to remove the Referer header
without using a proxy service. Apparently this code worked for one person:
var uri = new Uri ("http://some.where");
var request = WebRequestCreator.ClientHttp.Create (uri) as HttpWebRequest;
request.Headers ["user-agent"] = "My user agent string";
request.BeginGetResponse (...);
However, it seems that the general consensus in that thread is that there's no way to change it, but it should be fixed in the Mango
version.
Instead of request.Referer = referer
use request.Headers[HttpRequestHeader.Referer] = referer
and it will work
精彩评论