English 中文(简体)
如何通过GET从C号向PPI发出里程要求,并取得被装成行的果园?
原标题:How to send uri request via a GET from C# to PHP and get chars encoded as a browser does?
  • 时间:2012-01-12 19:05:59
  •  标签:
  • .net
  • web

我正在从C#中提一下GET。

var result = webClient.DownloadString(
 Microsoft.JScript.GlobalObject.encodeURI(
   "http://www.example.com?value=contacts[contact][0][name]=test man"
);

This results in the recieving PHP site: "value=contacts%5Bcontact%5D%5B0%5D%5Bname%5D=test%20man"

PHP脱节后

urldecode($value)

“数值=接触率%5Bcontact%5D%5B0%5D%5B 名义%5D=试验人”

因此,[......]错误

But when i paste the url in a browser (IE8 or Chrome) i get this results in the recieving PHP site: "value=contacts[contact][0][name]=test%20man"

IE. The browser sends the request (url) in a workable encoding, my code does not.

我如何以正确的编码来利用GET,正如浏览器所做的那样?

最佳回答

It was a lot of chars that had higher Code Points, that needs a %25 infront to parse right in PHP. Ex. å = %C3%E5 in encoding .NET but shold be: %25C3%25E5

So I made a function for correcting this, it is not complete for reuse, but will be if all other codes are added.

        var urlCodes = new [] { "20", "C3", "84", "85", "96", "A4", "A5", "B6", "2C", "C2", "A0", "2F", "40", "3A" };

        foreach (var stringsUrlCodes in urlCodes)
        {
            encodedUrl = encodedUrl.Replace("%" + stringsUrlCodes.ToString(), "%25" + stringsUrlCodes.ToString().Replace("%", string.Empty));
        }
问题回答

暂无回答




相关问题
Manually implementing high performance algorithms in .NET

As a learning experience I recently tried implementing Quicksort with 3 way partitioning in C#. Apart from needing to add an extra range check on the left/right variables before the recursive call, ...

Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How do I compare two decimals to 10 decimal places?

I m using decimal type (.net), and I want to see if two numbers are equal. But I only want to be accurate to 10 decimal places. For example take these three numbers. I want them all to be equal. 0....

Exception practices when creating a SynchronizationContext?

I m creating an STA version of the SynchronizationContext for use in Windows Workflow 4.0. I m wondering what to do about exceptions when Post-ing callbacks. The SynchronizationContext can be used ...

Show running instance in single instance application

I am building an application with C#. I managed to turn this into a single instance application by checking if the same process is already running. Process[] pname = Process.GetProcessesByName("...

How to combine DataTrigger and EventTrigger?

NOTE I have asked the related question (with an accepted answer): How to combine DataTrigger and Trigger? I think I need to combine an EventTrigger and a DataTrigger to achieve what I m after: when ...

热门标签