开发者

Mono - Uri class

开发者 https://www.devze.com 2023-02-03 21:01 出处:网络
I am making an HttpWebRequest at a url similar to this: \"http://mysite.com/search?query=my+search+string\"

I am making an HttpWebRequest at a url similar to this:

"http://mysite.com/search?query=my+search+string"

Problem is, the Uri class escapes it with %, and the site I'm making the request against can't handle the escaped characters. (I have no control to fix the site)

So tried this [Obsolete] constructor:

new Uri(myUriString, true);

But it did not seem to make any difference, when debugging, my Uri still got escaped.

I am running this on a Mac with Mono, but开发者_C百科 I have not tried it on standard .Net on Windows to see if it has the same behavior.

Is there another way to get around this issue?


I ran

Uri uri = new Uri("http://mysite.com/search?query=my+search+string");
Console.WriteLine(uri.ToString());

through Microsoft .NET Runtime and Mono on a Windows 7 machine and it did not escape the characters. Are you sure this URL isn't getting appended to another url where it thinks this is a query parameter?


Sadly, I don't see a way around this. Escaping characters via hexcodes is in the Uri spec and should be adhered by the server.

0

精彩评论

暂无评论...
验证码 换一张
取 消